Class: Spree::Stock::InventoryUnitBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ InventoryUnitBuilder

Returns a new instance of InventoryUnitBuilder



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

def initialize(order)
  @order = order
end

Instance Method Details

#unitsObject



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

def units
  @order.line_items.flat_map do |line_item|
    Array.new(line_item.quantity) do
      Spree::InventoryUnit.new(
        pending: true,
        variant: line_item.variant,
        line_item: line_item
      )
    end
  end
end