Sha256: 0929ea14b881911bd76c74d77d6518e4bb2d5164d2ca3a90c61289bd8050f7a3

Contents?: true

Size: 1.08 KB

Versions: 33

Compression:

Stored size: 1.08 KB

Contents

module Spree
  module Stock
    class Prioritizer
      attr_reader :packages, :inventory_units

      def initialize(inventory_units, packages, adjuster_class = Adjuster)
        @inventory_units = inventory_units
        @packages = packages
        @adjuster_class = adjuster_class
      end

      def prioritized_packages
        sort_packages
        adjust_packages
        prune_packages
        packages
      end

      private

      def adjust_packages
        inventory_units.each do |inventory_unit|
          adjuster = @adjuster_class.new(inventory_unit, :on_hand)

          visit_packages(adjuster)

          adjuster.status = :backordered
          visit_packages(adjuster)
        end
      end

      def visit_packages(adjuster)
        packages.each do |package|
          item = package.find_item adjuster.inventory_unit, adjuster.status
          adjuster.adjust(package) if item
        end
      end

      def sort_packages
        # order packages by preferred stock_locations
      end

      def prune_packages
        packages.reject!(&:empty?)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
solidus_core-2.3.1 app/models/spree/stock/prioritizer.rb
solidus_core-2.2.2 app/models/spree/stock/prioritizer.rb
solidus_core-2.1.1 app/models/spree/stock/prioritizer.rb
solidus_core-2.0.3 app/models/spree/stock/prioritizer.rb
solidus_core-1.4.2 app/models/spree/stock/prioritizer.rb
solidus_core-1.3.2 app/models/spree/stock/prioritizer.rb
solidus_legacy_stock_system-1.0.0 app/models/spree/stock/prioritizer.rb
solidus_core-2.3.0 app/models/spree/stock/prioritizer.rb
solidus_core-2.3.0.rc3 app/models/spree/stock/prioritizer.rb
solidus_core-2.3.0.rc2 app/models/spree/stock/prioritizer.rb
solidus_core-2.3.0.rc1 app/models/spree/stock/prioritizer.rb
solidus_core-2.3.0.beta1 app/models/spree/stock/prioritizer.rb
solidus_core-2.0.2 app/models/spree/stock/prioritizer.rb
solidus_core-1.4.1 app/models/spree/stock/prioritizer.rb
solidus_core-2.2.1 app/models/spree/stock/prioritizer.rb
solidus_core-2.2.0 app/models/spree/stock/prioritizer.rb
solidus_core-2.2.0.rc1 app/models/spree/stock/prioritizer.rb
solidus_core-2.2.0.beta1 app/models/spree/stock/prioritizer.rb
solidus_core-2.1.0 app/models/spree/stock/prioritizer.rb
solidus_core-2.1.0.rc1 app/models/spree/stock/prioritizer.rb