Class: Spree::Stock::Packer
- Inherits:
-
Object
- Object
- Spree::Stock::Packer
- Defined in:
- app/models/spree/stock/packer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#splitters ⇒ Object
readonly
Returns the value of attribute splitters.
-
#stock_location ⇒ Object
readonly
Returns the value of attribute stock_location.
Instance Method Summary collapse
- #default_package ⇒ Object
-
#initialize(stock_location, order, splitters = [Splitter::Base]) ⇒ Packer
constructor
A new instance of Packer.
- #packages ⇒ Object
Constructor Details
#initialize(stock_location, order, splitters = [Splitter::Base]) ⇒ Packer
Returns a new instance of Packer.
6 7 8 9 10 |
# File 'app/models/spree/stock/packer.rb', line 6 def initialize(stock_location, order, splitters=[Splitter::Base]) @stock_location = stock_location @order = order @splitters = splitters end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def order @order end |
#splitters ⇒ Object (readonly)
Returns the value of attribute splitters.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def splitters @splitters end |
#stock_location ⇒ Object (readonly)
Returns the value of attribute stock_location.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def stock_location @stock_location end |
Instance Method Details
#default_package ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/spree/stock/packer.rb', line 16 def default_package package = Package.new(stock_location, order) order.line_items.each do |line_item| next unless stock_location.stock_item(line_item.variant) on_hand, backordered = stock_location.fill_status(line_item.variant, line_item.quantity) package.add line_item.variant, on_hand, :on_hand if on_hand > 0 package.add line_item.variant, backordered, :backordered if backordered > 0 end package end |
#packages ⇒ Object
12 13 14 |
# File 'app/models/spree/stock/packer.rb', line 12 def packages build_splitter.split [default_package] end |