Class: Spree::Stock::Coordinator
- Inherits:
-
Object
- Object
- Spree::Stock::Coordinator
- Defined in:
- app/models/spree/stock/coordinator.rb
Instance Attribute Summary collapse
-
#allocated_inventory_units ⇒ Object
readonly
Returns the value of attribute allocated_inventory_units.
-
#inventory_units ⇒ Object
readonly
Returns the value of attribute inventory_units.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #build_packages(packages = Array.new) ⇒ Object
-
#initialize(order, inventory_units = nil) ⇒ Coordinator
constructor
A new instance of Coordinator.
- #packages ⇒ Object
- #shipments ⇒ Object
Constructor Details
#initialize(order, inventory_units = nil) ⇒ Coordinator
Returns a new instance of Coordinator.
6 7 8 9 10 |
# File 'app/models/spree/stock/coordinator.rb', line 6 def initialize(order, inventory_units = nil) @order = order @inventory_units = inventory_units || InventoryUnitBuilder.new(order).units @allocated_inventory_units = [] end |
Instance Attribute Details
#allocated_inventory_units ⇒ Object (readonly)
Returns the value of attribute allocated_inventory_units.
4 5 6 |
# File 'app/models/spree/stock/coordinator.rb', line 4 def allocated_inventory_units @allocated_inventory_units end |
#inventory_units ⇒ Object (readonly)
Returns the value of attribute inventory_units.
4 5 6 |
# File 'app/models/spree/stock/coordinator.rb', line 4 def inventory_units @inventory_units end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/models/spree/stock/coordinator.rb', line 4 def order @order end |
Instance Method Details
#build_packages(packages = Array.new) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/models/spree/stock/coordinator.rb', line 24 def build_packages(packages = Array.new) stock_locations_with_requested_variants.each do |stock_location| packer = build_packer(stock_location, unallocated_inventory_units) packages += packer.packages @allocated_inventory_units += packer.allocated_inventory_units end packages end |
#packages ⇒ Object
18 19 20 21 22 |
# File 'app/models/spree/stock/coordinator.rb', line 18 def packages packages = build_packages packages = prioritize_packages(packages) packages = estimate_packages(packages) end |
#shipments ⇒ Object
12 13 14 15 16 |
# File 'app/models/spree/stock/coordinator.rb', line 12 def shipments packages.map do |package| package.to_shipment.tap { |s| s.address = order.ship_address } end end |