spree_winkelstraat 3.1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +53 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_winkelstraat.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_winkelstraat.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_winkelstraat.css +4 -0
- data/app/assets/stylesheets/spree/frontend/spree_winkelstraat.css +4 -0
- data/app/controllers/api/v1/orders_controller_decorator.rb +15 -0
- data/app/controllers/api/v1/products_controller_decorator.rb +13 -0
- data/app/models/spree/order/mail_defuser.rb +15 -0
- data/app/models/spree/order_decorator.rb +180 -0
- data/app/models/spree/product_decorator.rb +110 -0
- data/app/models/spree/promotion/rules/not_winkelstraat_order.rb +18 -0
- data/app/models/spree/reimbursement/mail_defuser.rb +9 -0
- data/app/models/spree/reimbursement_decorator.rb +5 -0
- data/app/models/spree/shipment_handler/mail_defuser.rb +7 -0
- data/app/models/spree/shipment_handler_decorator.rb +5 -0
- data/app/models/spree/variant_decorator.rb +51 -0
- data/app/overrides/option_value_fields.rb +13 -0
- data/app/overrides/order_index.rb +13 -0
- data/app/overrides/product_form.rb +6 -0
- data/app/views/spree/admin/option_types/_extra_option_value_fields.html.erb +1 -0
- data/app/views/spree/admin/option_types/_extra_option_value_headers.html.erb +1 -0
- data/app/views/spree/admin/orders/_index_tradebyte_state_override.html.erb +7 -0
- data/app/views/spree/admin/orders/_index_tradebyte_state_override_head.html.erb +1 -0
- data/app/views/spree/admin/products/_sell_on_winkelstraat.html.erb +7 -0
- data/app/views/spree/admin/promotions/rules/_not_winkelstraat_order.html.erb +0 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +18 -0
- data/db/migrate/20190424140108_add_winkelstraat_data.rb +5 -0
- data/db/migrate/20190429134248_add_ws_code_to_option_values.rb +5 -0
- data/db/migrate/20190501101657_add_winkelstraat_taxons.rb +24 -0
- data/db/migrate/20190501122837_add_winkelstraat_payment_method_and_shipping_method.rb +11 -0
- data/db/migrate/20190507114902_add_active_on_winkelstraat_to_spree_products.rb +5 -0
- data/lib/generators/spree_winkelstraat/install/install_generator.rb +31 -0
- data/lib/spree_winkelstraat/engine.rb +26 -0
- data/lib/spree_winkelstraat/factories.rb +6 -0
- data/lib/spree_winkelstraat/order_importer.rb +65 -0
- data/lib/spree_winkelstraat.rb +3 -0
- data/spec/spec_helper.rb +93 -0
- data/spree_winkelstraat.gemspec +33 -0
- metadata +257 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 474c043df609e402e78963ae719e3f3df6f234f5c50929ed67c1c888f601b394
         | 
| 4 | 
            +
              data.tar.gz: 14d6b9d2860666f9f800eb75026e66050cd74f0be0c3fc0ab89a4e4c4fbd2d6d
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: cb308272b9596335d80f130a38cf15303fb3c6878ceed9d22f4836c47c2264beec9b09518d40b27350c7f667a29c647078676002ad10e53449e96f9fa952381d
         | 
| 7 | 
            +
              data.tar.gz: acf83a91851d735b9a75ecd0c32cb33db19fa63fe643aeb4bc7912907eb7317a898378ac8b9f7da874ed75532c159fb1d49449eed8c8ef69131d10cccbd7765b
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            --color
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            Copyright (c) 2019 [name of plugin creator]
         | 
| 2 | 
            +
            All rights reserved.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Redistribution and use in source and binary forms, with or without modification,
         | 
| 5 | 
            +
            are permitted provided that the following conditions are met:
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                * Redistributions of source code must retain the above copyright notice,
         | 
| 8 | 
            +
                  this list of conditions and the following disclaimer.
         | 
| 9 | 
            +
                * Redistributions in binary form must reproduce the above copyright notice,
         | 
| 10 | 
            +
                  this list of conditions and the following disclaimer in the documentation
         | 
| 11 | 
            +
                  and/or other materials provided with the distribution.
         | 
| 12 | 
            +
                * Neither the name Spree nor the names of its contributors may be used to
         | 
| 13 | 
            +
                  endorse or promote products derived from this software without specific
         | 
| 14 | 
            +
                  prior written permission.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
         | 
| 17 | 
            +
            "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
         | 
| 18 | 
            +
            LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
         | 
| 19 | 
            +
            A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
         | 
| 20 | 
            +
            CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
         | 
| 21 | 
            +
            EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
         | 
| 22 | 
            +
            PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
         | 
| 23 | 
            +
            PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
         | 
| 24 | 
            +
            LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
         | 
| 25 | 
            +
            NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
         | 
| 26 | 
            +
            SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            SpreeWinkelstraat
         | 
| 2 | 
            +
            =================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Introduction goes here.
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            ## Installation
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            1. Add this extension to your Gemfile with this line:
         | 
| 9 | 
            +
              ```ruby
         | 
| 10 | 
            +
              gem 'spree_winkelstraat', github: '[your-github-handle]/spree_winkelstraat', branch: 'X-X-stable'
         | 
| 11 | 
            +
              ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              The `branch` option is important: it must match the version of Spree you're using.
         | 
| 14 | 
            +
              For example, use `3-1-stable` if you're using Spree `3-1-stable` or any `3.1.x` version.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            2. Install the gem using Bundler:
         | 
| 17 | 
            +
              ```ruby
         | 
| 18 | 
            +
              bundle install
         | 
| 19 | 
            +
              ```
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            3. Copy & run migrations
         | 
| 22 | 
            +
              ```ruby
         | 
| 23 | 
            +
              bundle exec rails g spree_winkelstraat:install
         | 
| 24 | 
            +
              ```
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            4. Restart your server
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              If your server was running, restart it so that it can find the assets properly.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ## Testing
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            ```shell
         | 
| 35 | 
            +
            bundle
         | 
| 36 | 
            +
            bundle exec rake
         | 
| 37 | 
            +
            ```
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            When testing your applications integration with this extension you may use it's factories.
         | 
| 40 | 
            +
            Simply add this require statement to your spec_helper:
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ```ruby
         | 
| 43 | 
            +
            require 'spree_winkelstraat/factories'
         | 
| 44 | 
            +
            ```
         | 
| 45 | 
            +
             | 
| 46 | 
            +
             | 
| 47 | 
            +
            ## Contributing
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            If you'd like to contribute, please take a look at the
         | 
| 50 | 
            +
            [instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
         | 
| 51 | 
            +
            pull request.
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            Copyright (c) 2019 [name of extension creator], released under the New BSD License
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'bundler'
         | 
| 2 | 
            +
            Bundler::GemHelper.install_tasks
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'rspec/core/rake_task'
         | 
| 5 | 
            +
            require 'spree/testing_support/extension_rake'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            RSpec::Core::RakeTask.new
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            task :default do
         | 
| 10 | 
            +
              if Dir["spec/dummy"].empty?
         | 
| 11 | 
            +
                Rake::Task[:test_app].invoke
         | 
| 12 | 
            +
                Dir.chdir("../../")
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              Rake::Task[:spec].invoke
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            desc 'Generates a dummy app for testing'
         | 
| 18 | 
            +
            task :test_app do
         | 
| 19 | 
            +
              ENV['LIB_NAME'] = 'spree_winkelstraat'
         | 
| 20 | 
            +
              Rake::Task['extension:test_app'].invoke
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            Spree::Api::V1::OrdersController.class_eval do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              skip_before_action :find_order, only: [:import]
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def import
         | 
| 6 | 
            +
                begin
         | 
| 7 | 
            +
                  order_params = Spree::Order.winkelstraat_to_order_params(params)
         | 
| 8 | 
            +
                  @order = SpreeWinkelstraat::OrderImporter.import(nil, order_params)
         | 
| 9 | 
            +
                  render :show
         | 
| 10 | 
            +
                rescue Exception => e
         | 
| 11 | 
            +
                  error_during_processing(e)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            Spree::Api::V1::ProductsController.class_eval do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def winkelstraat_stock
         | 
| 4 | 
            +
                csv = Spree::Variant.winkelstraat_stock_csv
         | 
| 5 | 
            +
                send_data csv, filename: "ws-stock-#{Date.today}.csv"
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def winkelstraat_article
         | 
| 9 | 
            +
                csv = Spree::Product.winkelstraat_csv
         | 
| 10 | 
            +
                send_data csv, filename: "ws-articles-#{Date.today}.csv"
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,180 @@ | |
| 1 | 
            +
            Spree::Order.class_eval do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              self.prepend(Spree::Order::MailDefuser)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def is_winkelstraat_order?
         | 
| 6 | 
            +
                winkelstraat_order_id.present?
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              class << self
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                # {
         | 
| 12 | 
            +
                #     "id":"401292144",
         | 
| 13 | 
            +
                #     "date":"2019-04-06T20:35:05+02:00",
         | 
| 14 | 
            +
                #     "items":[
         | 
| 15 | 
            +
                #         {
         | 
| 16 | 
            +
                #             "sku":"32963-40",
         | 
| 17 | 
            +
                #             "reference":"00002795 AZ",
         | 
| 18 | 
            +
                #             "article_number":"00002795",
         | 
| 19 | 
            +
                #             "manufacturer":"Dsquared2",
         | 
| 20 | 
            +
                #             "name":"Jeans met leg pattern",
         | 
| 21 | 
            +
                #             "size":"IT 50",
         | 
| 22 | 
            +
                #             "color":"Blauw",
         | 
| 23 | 
            +
                #             "quantity":1,
         | 
| 24 | 
            +
                #             "price":718
         | 
| 25 | 
            +
                #         }
         | 
| 26 | 
            +
                #     ],
         | 
| 27 | 
            +
                #     "discount":0,
         | 
| 28 | 
            +
                #     "grand_total":718,
         | 
| 29 | 
            +
                #     "shipping_method":null,
         | 
| 30 | 
            +
                #     "picking_pdf_url":"https:\/\/www.winkelstraat.nl\/pushapi\/order\/download\/0%3A2%3Aaeed630c14ba637b%3AHK6I26xV2rwoECXttEr5dQ%3D%3D\/2534447b7eef8a7e0878e6195fc7be470d1a07e0b4549e25784bc3816d031c45:yeLKFkZerl1XlrWKNTYR8qz5BNKWEw7v",
         | 
| 31 | 
            +
                #     "shipping_address":{
         | 
| 32 | 
            +
                #         "name":"Test de Test",
         | 
| 33 | 
            +
                #         "street":"J.J.A. Winkelstraat",
         | 
| 34 | 
            +
                #         "housenumber":"5",
         | 
| 35 | 
            +
                #         "postcode":"3494RK",
         | 
| 36 | 
            +
                #         "city":"Ergens",
         | 
| 37 | 
            +
                #         "province":null,
         | 
| 38 | 
            +
                #         "country":"NL",
         | 
| 39 | 
            +
                #         "email":"service@Winkelstraat.nl"
         | 
| 40 | 
            +
                #     }
         | 
| 41 | 
            +
                # }
         | 
| 42 | 
            +
                def winkelstraat_to_order_params(params)
         | 
| 43 | 
            +
                  order_params = {}
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  order_params[:winkelstraat_order_id] = params['id']
         | 
| 46 | 
            +
                  order_params[:completed_at] = DateTime.parse(params['date'])
         | 
| 47 | 
            +
                  order_params[:email] = params['shipping_address']['email']
         | 
| 48 | 
            +
                  order_params[:winkelstraat_order_id] = params['id']
         | 
| 49 | 
            +
                  order_params[:use_billing] = true
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  order_params[:bill_address_attributes] = build_address(params['shipping_address'])
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  order_params[:shipments_attributes] = build_shipments_attributes(params, 'Amstelveen')
         | 
| 54 | 
            +
                  order_params[:payments_attributes] = build_payments_attributes(params)
         | 
| 55 | 
            +
                  order_params[:line_items_attributes] = build_line_items_attributes(params)
         | 
| 56 | 
            +
                  order_params[:adjustments_attributes] = build_adjustments_attributes(params)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  order_params
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                # private
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def build_address(address_params)
         | 
| 64 | 
            +
                  {
         | 
| 65 | 
            +
                      firstname: address_params['name'].split(' ').first,
         | 
| 66 | 
            +
                      lastname: address_params['name'].split(' ')[1..-1].join(' '),
         | 
| 67 | 
            +
                      address1: address_params['street'],
         | 
| 68 | 
            +
                      address2: address_params['housenumber'],
         | 
| 69 | 
            +
                      city: address_params['city'],
         | 
| 70 | 
            +
                      zipcode: address_params['postcode'],
         | 
| 71 | 
            +
                      phone: '0612345678',
         | 
| 72 | 
            +
                      country: {
         | 
| 73 | 
            +
                          'iso' => address_params['country']
         | 
| 74 | 
            +
                      }
         | 
| 75 | 
            +
                  }
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                #     "shipments_attributes": [
         | 
| 79 | 
            +
                #       {
         | 
| 80 | 
            +
                #         "tracking": "track track track",
         | 
| 81 | 
            +
                #         "stock_location": "default",
         | 
| 82 | 
            +
                #         "cost": 11,
         | 
| 83 | 
            +
                #         "shipping_method": "UPS Ground (USD)",
         | 
| 84 | 
            +
                #         "inventory_units": [
         | 
| 85 | 
            +
                #           { "variant_id": "1" },
         | 
| 86 | 
            +
                #           { "variant_id": "2" },
         | 
| 87 | 
            +
                #           { "variant_id": "2" },
         | 
| 88 | 
            +
                #           { "variant_id": "2" },
         | 
| 89 | 
            +
                #           { "variant_id": "2" },
         | 
| 90 | 
            +
                #           { "variant_id": "3" },
         | 
| 91 | 
            +
                #           { "variant_id": "4" },
         | 
| 92 | 
            +
                #           { "variant_id": "5" }
         | 
| 93 | 
            +
                #         ]
         | 
| 94 | 
            +
                #       }
         | 
| 95 | 
            +
                #     ],
         | 
| 96 | 
            +
                def build_shipments_attributes(params, stock_location_name)
         | 
| 97 | 
            +
                  [
         | 
| 98 | 
            +
                      {
         | 
| 99 | 
            +
                          tracking: nil,
         | 
| 100 | 
            +
                          stock_location: stock_location_name,
         | 
| 101 | 
            +
                          shipping_method: 'Winkelstraat shipping',
         | 
| 102 | 
            +
                          inventory_units: params['items'].map do |item|
         | 
| 103 | 
            +
                            item['quantity'].times.map do
         | 
| 104 | 
            +
                              {
         | 
| 105 | 
            +
                                  sku: item['sku']
         | 
| 106 | 
            +
                              }
         | 
| 107 | 
            +
                            end
         | 
| 108 | 
            +
                          end.flatten
         | 
| 109 | 
            +
                      }
         | 
| 110 | 
            +
                  ]
         | 
| 111 | 
            +
                end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                #     "payments_attributes": [
         | 
| 114 | 
            +
                #       {
         | 
| 115 | 
            +
                #         "number": "REGE345546FDF",
         | 
| 116 | 
            +
                #         "state": "completed",
         | 
| 117 | 
            +
                #         "amount": 480.90,
         | 
| 118 | 
            +
                #         "payment_method": "Authorize.Net"
         | 
| 119 | 
            +
                #       },
         | 
| 120 | 
            +
                #       {
         | 
| 121 | 
            +
                #         "number": "ERERGREG43534DF",
         | 
| 122 | 
            +
                #         "state": "void",
         | 
| 123 | 
            +
                #         "amount": 46.95,
         | 
| 124 | 
            +
                #         "payment_method": "Authorize.Net"
         | 
| 125 | 
            +
                #       }
         | 
| 126 | 
            +
                #     ],
         | 
| 127 | 
            +
                def build_payments_attributes(params)
         | 
| 128 | 
            +
                  [
         | 
| 129 | 
            +
                      {
         | 
| 130 | 
            +
                          amount: params['grand_total'],
         | 
| 131 | 
            +
                          state: 'completed',
         | 
| 132 | 
            +
                          payment_method: 'Paid at winkelstraat'
         | 
| 133 | 
            +
                      }
         | 
| 134 | 
            +
                  ]
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                #     "line_items_attributes": {
         | 
| 138 | 
            +
                #       "0": {
         | 
| 139 | 
            +
                #         "variant_id": "1",
         | 
| 140 | 
            +
                #         "quantity": 1,
         | 
| 141 | 
            +
                #         "price": 50
         | 
| 142 | 
            +
                #       },
         | 
| 143 | 
            +
                #       "3": {
         | 
| 144 | 
            +
                #         "variant_id": "2",
         | 
| 145 | 
            +
                #         "quantity": 4,
         | 
| 146 | 
            +
                #         "price": 60
         | 
| 147 | 
            +
                #       },
         | 
| 148 | 
            +
                #     },
         | 
| 149 | 
            +
                def build_line_items_attributes(params)
         | 
| 150 | 
            +
                  params['items'].map do |item|
         | 
| 151 | 
            +
                    variant = Spree::Variant.active.find_by_sku(item['sku'])
         | 
| 152 | 
            +
                    next if variant.blank?
         | 
| 153 | 
            +
                    {
         | 
| 154 | 
            +
                        variant_id: variant.id,
         | 
| 155 | 
            +
                        quantity: item['quantity'],
         | 
| 156 | 
            +
                        price: item['price']
         | 
| 157 | 
            +
                    }
         | 
| 158 | 
            +
                  end.compact
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                # "adjustments_attributes": [
         | 
| 162 | 
            +
                #       {
         | 
| 163 | 
            +
                #         "label": "tax",
         | 
| 164 | 
            +
                #         "amount": 0
         | 
| 165 | 
            +
                #       },
         | 
| 166 | 
            +
                #       {
         | 
| 167 | 
            +
                #         "label": "something",
         | 
| 168 | 
            +
                #         "amount": 17.9
         | 
| 169 | 
            +
                #       }
         | 
| 170 | 
            +
                #     ],
         | 
| 171 | 
            +
                def build_adjustments_attributes(params)
         | 
| 172 | 
            +
                  [
         | 
| 173 | 
            +
                      {
         | 
| 174 | 
            +
                          label: 'Winkelstraat Discount',
         | 
| 175 | 
            +
                          amount: -(params['discount'].to_f.abs)
         | 
| 176 | 
            +
                      }
         | 
| 177 | 
            +
                  ]
         | 
| 178 | 
            +
                end
         | 
| 179 | 
            +
              end
         | 
| 180 | 
            +
            end
         | 
| @@ -0,0 +1,110 @@ | |
| 1 | 
            +
            Spree::Product.class_eval do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              WOMEN_CATEGORIES = ["Accessoires", "Badmode", "Blazers & Gilets", "Blouses", "Broeken", "Jassen", "Jeans",
         | 
| 4 | 
            +
                                  "Jumpsuits", "Jurken", "Lingerie", "Nachtmode", "Rokken", "Schoenen", "Sport", "Tassen", "Tops", "Truien & Vesten"]
         | 
| 5 | 
            +
              MEN_CATEGORIES = ["Accessoires", "Badmode", "Broeken", "Colberts & Gilets", "Jassen", "Jeans", "Ondergoed",
         | 
| 6 | 
            +
                                "Overhemden", "Schoenen", "Shirts", "Sport", "Truien", "Vesten"]
         | 
| 7 | 
            +
              KIDS_CATEGORIES = ["Jongens", "Meisjes"]
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              IMG_HOST = Rails.env.production? ? 'https://paulwarmer-production.imgix.net' : Settings.backend_url
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              class << self
         | 
| 12 | 
            +
                def winkelstraat_csv
         | 
| 13 | 
            +
                  products = Spree::Product.active.where(sell_on_winkelstraat: true)
         | 
| 14 | 
            +
                  variants = Spree::Variant.includes(:images, option_values: :translations, product: :translations).where(product: products, is_master: false)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  headings = [
         | 
| 17 | 
            +
                      'Productnaam',
         | 
| 18 | 
            +
                      'Winkel product nummer',
         | 
| 19 | 
            +
                      'EAN',
         | 
| 20 | 
            +
                      'Merk product nummer',
         | 
| 21 | 
            +
                      'Kassa referentie',
         | 
| 22 | 
            +
                      'Geslacht',
         | 
| 23 | 
            +
                      'Categorie',
         | 
| 24 | 
            +
                      'Subcategorie',
         | 
| 25 | 
            +
                      'Merk',
         | 
| 26 | 
            +
                      'Kleur',
         | 
| 27 | 
            +
                      'Prijs',
         | 
| 28 | 
            +
                      'Maatvoering',
         | 
| 29 | 
            +
                      'Materiaal',
         | 
| 30 | 
            +
                      'Pasvorm',
         | 
| 31 | 
            +
                      'Omschrijving',
         | 
| 32 | 
            +
                      'Maat op foto',
         | 
| 33 | 
            +
                      'Lengte',
         | 
| 34 | 
            +
                      'Breedte',
         | 
| 35 | 
            +
                      'Hoogte',
         | 
| 36 | 
            +
                      'Omvang',
         | 
| 37 | 
            +
                      'Seizoen',
         | 
| 38 | 
            +
                      'Carry over',
         | 
| 39 | 
            +
                      *(1..10).to_a.map {|i| "Afbeelding#{i}"},
         | 
| 40 | 
            +
                      *Spree::StockLocation.all.map {|sl| sl.name }
         | 
| 41 | 
            +
                  ]
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  women_taxon = Spree::Taxon.where(name: 'women').first
         | 
| 44 | 
            +
                  men_taxon = Spree::Taxon.where(name: 'men').first
         | 
| 45 | 
            +
                  kids_taxon = Spree::Taxon.where(name: 'kids').first
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  main_taxonomy = Spree::Taxonomy.where(name: 'Winkelstraat Category').first
         | 
| 48 | 
            +
                  brand_taxonomy = Spree::Taxonomy.where(name: 'Filter').first
         | 
| 49 | 
            +
                  brand_taxon_parent = Spree::Taxon.where(taxonomy: brand_taxonomy, name: 'Brands').try(:first)
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  season_taxonomy = Spree::Taxonomy.where(name: 'Season').first
         | 
| 52 | 
            +
             | 
| 53 | 
            +
             | 
| 54 | 
            +
                  CSV.generate(headers: true) do |csv|
         | 
| 55 | 
            +
                    csv << headings
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    variants.each do |variant|
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                      gender = case
         | 
| 60 | 
            +
                               when variant.in_taxon?(women_taxon)
         | 
| 61 | 
            +
                                 'D'
         | 
| 62 | 
            +
                               when variant.in_taxon?(men_taxon)
         | 
| 63 | 
            +
                                 'H'
         | 
| 64 | 
            +
                               when variant.in_taxon?(kids_taxon)
         | 
| 65 | 
            +
                                 'K'
         | 
| 66 | 
            +
                               else
         | 
| 67 | 
            +
                                 'D'
         | 
| 68 | 
            +
                               end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                      csv << [
         | 
| 71 | 
            +
                          variant.product.ws_compatible_name, #'Productnaam',
         | 
| 72 | 
            +
                          variant.id, #'Winkel product nummer',
         | 
| 73 | 
            +
                          variant.sku, # 'EAN',
         | 
| 74 | 
            +
                          variant.sku, # 'Merk product nummer',
         | 
| 75 | 
            +
                          variant.kassa_reference, # 'Kassa referentie',
         | 
| 76 | 
            +
                          gender, #Geslacht
         | 
| 77 | 
            +
                          variant.product.taxons.where(taxonomy: main_taxonomy, parent: main_taxonomy.root).first.try(:name), # 'Categorie',
         | 
| 78 | 
            +
                          variant.product.taxons.where(taxonomy: main_taxonomy).where.not(parent: nil).where.not(parent: main_taxonomy.root).first.try(:name), #'Subcategorie',
         | 
| 79 | 
            +
                          brand_taxon_parent.present? ? variant.product.taxons.where(parent: brand_taxon_parent).first.try(:name) : nil, #'Merk',
         | 
| 80 | 
            +
                          variant.option_values.joins(option_type: :translations).where(spree_option_type_translations: { name: 'color' }).first.try(:ws_code), #'Kleur',
         | 
| 81 | 
            +
                          variant.price, # 'Prijs',
         | 
| 82 | 
            +
                          'CF', #Maatvoering',
         | 
| 83 | 
            +
                          variant.product.product_properties.includes(property: :translations).where(spree_property_translations: {name: 'material'}).first.try(:value), #Materiaal',
         | 
| 84 | 
            +
                          variant.product.product_properties.includes(property: :translations).where(spree_property_translations: {name: 'fit'}).first.try(:value) || 'Dit item valt normaal', #Pasvorm',
         | 
| 85 | 
            +
                          ActionController::Base.helpers.strip_tags(variant.description), #'Omschrijving',
         | 
| 86 | 
            +
                          variant.product.variants.first.option_values.joins(option_type: :translations).where(spree_option_type_translations: { name: 'size' }).first.try(:presentation), #'Maat op foto',
         | 
| 87 | 
            +
                          variant.depth, #lengte
         | 
| 88 | 
            +
                          variant.width, #breedte
         | 
| 89 | 
            +
                          variant.height, #hoogte
         | 
| 90 | 
            +
                          nil, #'Omvang',
         | 
| 91 | 
            +
                          variant.product.taxons.where(taxonomy: season_taxonomy).first.try(:name), # 'Seizoen',Afbeeldingen
         | 
| 92 | 
            +
                          nil, #'Carry over',
         | 
| 93 | 
            +
                          *(variant.images.any? ? variant.images : variant.product.master.images).first(10).map do |image|
         | 
| 94 | 
            +
                            uri = URI.join(IMG_HOST, image.attachment(:original))
         | 
| 95 | 
            +
                            uri.query = URI.encode_www_form [['fm', 'jpg'], ['w', '1280'], ['h', '1920'], ['fit', 'clamp']]
         | 
| 96 | 
            +
                            uri.to_s
         | 
| 97 | 
            +
                          end,
         | 
| 98 | 
            +
                          *Spree::StockLocation.all.map {|sl| sl.count_on_hand(variant) || 0 }
         | 
| 99 | 
            +
                      ]
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                end
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              def ws_compatible_name
         | 
| 107 | 
            +
                name
         | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
            end
         |