Sha256: 5de10bf8686a6b55ae97af134624dbfbfa2150a8f464f38308c1ba2ff6a47984

Contents?: true

Size: 818 Bytes

Versions: 26

Compression:

Stored size: 818 Bytes

Contents

module Spree
  module Stock
    module Splitter
      class Digital < Spree::Stock::Splitter::Base
        def split(packages)
          split_packages = []
          packages.each do |package|
            split_packages += split_by_digital(package)
          end

          return_next(split_packages)
        end

        private

        def split_by_digital(package)
          digitals = Hash.new { |hash, key| hash[key] = [] }
          package.contents.each do |item|
            digitals[item.variant.digital?] << item
          end

          hash_to_packages(digitals)
        end

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/stock/splitter/digital.rb
spree_core-4.10.0 app/models/spree/stock/splitter/digital.rb
spree_core-4.9.0 app/models/spree/stock/splitter/digital.rb
spree_core-4.8.3 app/models/spree/stock/splitter/digital.rb
spree_core-4.8.2 app/models/spree/stock/splitter/digital.rb
spree_core-4.7.3 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.6 app/models/spree/stock/splitter/digital.rb
spree_core-4.5.5 app/models/spree/stock/splitter/digital.rb
spree_core-4.4.1 app/models/spree/stock/splitter/digital.rb
spree_core-4.5.4 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.5 app/models/spree/stock/splitter/digital.rb
spree_core-4.7.2 app/models/spree/stock/splitter/digital.rb
spree_core-4.7.1 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.4 app/models/spree/stock/splitter/digital.rb
spree_core-4.7.0 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.3 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.2 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.1 app/models/spree/stock/splitter/digital.rb
spree_core-4.6.0 app/models/spree/stock/splitter/digital.rb
spree_core-4.5.3 app/models/spree/stock/splitter/digital.rb