Sha256: 647fe7694bdfbf3e683614c437410fc1edbdc6e53f234241642461d1863cebcb

Contents?: true

Size: 880 Bytes

Versions: 9

Compression:

Stored size: 880 Bytes

Contents

# frozen_string_literal: true

module Spree
  module Stock
    module Splitter
      class ShippingCategory < Spree::Stock::Splitter::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_value do |contents|
            packages << build_package(contents)
          end
          packages
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
solidus_core-4.4.1 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.4.0 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.3.4 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.2.4 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.1.5 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.3.3 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.3.2 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.3.1 app/models/spree/stock/splitter/shipping_category.rb
solidus_core-4.3.0 app/models/spree/stock/splitter/shipping_category.rb