Module: SolidusProductAssembly::Spree::InventoryUnitDecorator

Defined in:
app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb

Instance Method Summary collapse

Instance Method Details

#percentage_of_line_itemObject



6
7
8
9
10
11
12
13
14
# File 'app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb', line 6

def percentage_of_line_item
  product = line_item.product
  if product.assembly?
    total_value = line_item.quantity_by_variant.map { |part, quantity| part.price * quantity }.sum
    variant.price / total_value
  else
    1 / BigDecimal(line_item.quantity)
  end
end