Class: Spree::Stock::RemainingPacker

Inherits:
Packer
  • Object
show all
Defined in:
app/models/spree/stock/remaining_packer.rb

Instance Attribute Summary collapse

Attributes inherited from Packer

#order, #splitters, #stock_location

Instance Method Summary collapse

Methods inherited from Packer

#packages

Constructor Details

#initialize(stock_location, order, order_counter = nil) ⇒ RemainingPacker


6
7
8
9
# File 'app/models/spree/stock/remaining_packer.rb', line 6

def initialize(stock_location, order, order_counter=nil)
  super
  @order_counter = order_counter || Stock::OrderCounter.new(order)
end

Instance Attribute Details

#order_counterObject (readonly)

Returns the value of attribute order_counter


4
5
6
# File 'app/models/spree/stock/remaining_packer.rb', line 4

def order_counter
  @order_counter
end

Instance Method Details

#default_packageObject


11
12
13
14
15
16
17
18
19
# File 'app/models/spree/stock/remaining_packer.rb', line 11

def default_package
  package = Package.new(stock_location, order)
  order_counter.variants_with_remaining.each do |variant|
    on_hand, backordered = stock_status(variant, order_counter.remaining(variant))
    package.add variant, on_hand, :on_hand if on_hand > 0
    package.add variant, backordered, :backordered if backordered > 0
  end
  package
end