Sha256: 898ae131aa166a6f2d0726f38003b18e8c4e00239bec5d2edcc0418797ac84db

Contents?: true

Size: 1.06 KB

Versions: 57

Compression:

Stored size: 1.06 KB

Contents

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

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

      def prioritized_packages
        sort_packages
        adjust_packages
        prune_packages
        packages
      end

      private
      def adjust_packages
        order.line_items.each do |line_item|
          adjuster = @adjuster_class.new(line_item.variant, line_item.quantity, :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.variant, adjuster.status
          adjuster.adjust(item) if item
        end
      end

      def sort_packages
        # order packages by preferred stock_locations
      end

      def prune_packages
        packages.reject! { |pkg| pkg.empty? }
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
spree_core-2.3.13 app/models/spree/stock/prioritizer.rb
spree_core-2.2.14 app/models/spree/stock/prioritizer.rb
spree_core-2.3.12 app/models/spree/stock/prioritizer.rb
spree_core-2.2.13 app/models/spree/stock/prioritizer.rb
spree_core-2.3.11 app/models/spree/stock/prioritizer.rb
spree_core-2.2.12 app/models/spree/stock/prioritizer.rb
spree_core-2.3.10 app/models/spree/stock/prioritizer.rb
spree_core-2.3.9 app/models/spree/stock/prioritizer.rb
spree_core-2.2.11 app/models/spree/stock/prioritizer.rb
spree_core-2.2.10 app/models/spree/stock/prioritizer.rb
spree_core-2.3.8 app/models/spree/stock/prioritizer.rb
spree_core-2.3.7 app/models/spree/stock/prioritizer.rb
spree_core-2.2.9 app/models/spree/stock/prioritizer.rb
spree_core-2.1.12 app/models/spree/stock/prioritizer.rb
spree_core-2.3.6 app/models/spree/stock/prioritizer.rb
spree_core-2.2.8 app/models/spree/stock/prioritizer.rb
spree_core-2.1.11 app/models/spree/stock/prioritizer.rb
spree_core-2.3.5 app/models/spree/stock/prioritizer.rb
spree_core-2.2.7 app/models/spree/stock/prioritizer.rb
spree_core-2.1.10 app/models/spree/stock/prioritizer.rb