Sha256: aaf09d935cc27395f9b64d9ab885bedd8a74429d3fe2b5f98b545a97936d14b5

Contents?: true

Size: 726 Bytes

Versions: 133

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true

module Spree
  module Stock
    module Splitter
      class Weight < Spree::Stock::Splitter::Base
        cattr_accessor :threshold do
          150
        end

        def split(packages)
          packages.each do |package|
            removed_contents = reduce package
            packages << build_package(removed_contents) unless removed_contents.empty?
          end
          return_next packages
        end

        private

        def reduce(package)
          removed = []
          while package.weight > threshold
            break if package.contents.size == 1
            removed << package.contents.shift
          end
          removed
        end
      end
    end
  end
end

Version data entries

133 entries across 133 versions & 2 rubygems

Version Path
solidus_core-3.3.0 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.5 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.4 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.3 app/models/spree/stock/splitter/weight.rb
solidus_core-3.1.8 app/models/spree/stock/splitter/weight.rb
solidus_core-3.0.8 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.2 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.1 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.0 app/models/spree/stock/splitter/weight.rb
solidus_core-3.2.0.alpha app/models/spree/stock/splitter/weight.rb
solidus_core-3.0.7 app/models/spree/stock/splitter/weight.rb
solidus_core-2.11.17 app/models/spree/stock/splitter/weight.rb
solidus_core-3.1.7 app/models/spree/stock/splitter/weight.rb
solidus_core-2.11.16 app/models/spree/stock/splitter/weight.rb
solidus_core-3.0.6 app/models/spree/stock/splitter/weight.rb
solidus_core-3.1.6 app/models/spree/stock/splitter/weight.rb
solidus_core-2.11.15 app/models/spree/stock/splitter/weight.rb
solidus_core-2.11.14 app/models/spree/stock/splitter/weight.rb
solidus_core-3.0.5 app/models/spree/stock/splitter/weight.rb
solidus_core-3.1.5 app/models/spree/stock/splitter/weight.rb