Sha256: a81dea623464294e92be61d9e2381a5f69b1696523880b3703f9eb39662993e2

Contents?: true

Size: 822 Bytes

Versions: 43

Compression:

Stored size: 822 Bytes

Contents

module Spree
  module Stock
    module Splitter
      class ShippingCategory < Base
        def split(packages)
          split_packages = []
          packages.each do |package|
            split_packages += split_by_category(package)
          end
          return_next split_packages
        end

        private
        def split_by_category(package)
          categories = Hash.new { |hash, key| hash[key] = [] }
          package.contents.each do |item|
            categories[item.variant.shipping_category_id] << item
          end
          hash_to_packages(categories)
        end

        def hash_to_packages(categories)
          packages = []
          categories.each do |id, contents|
            packages << build_package(contents)
          end
          packages
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
spree_core-2.2.14 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.13 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.12 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.11 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.10 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.9 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.1.12 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.8 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.1.11 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.7 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.1.10 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.0.13 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.1.9 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.6 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.5 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.1.8 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.0.12 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.4 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.3 app/models/spree/stock/splitter/shipping_category.rb
spree_core-2.2.2 app/models/spree/stock/splitter/shipping_category.rb