Class: Spina::Shop::ProductBundle

Inherits:
ApplicationRecord show all
Defined in:
app/models/spina/shop/product_bundle.rb

Instance Method Summary collapse

Instance Method Details

#cost_priceObject



47
48
49
# File 'app/models/spina/shop/product_bundle.rb', line 47

def cost_price
  bundled_products.inject(BigDecimal(0)){|t, i| t + (i.product.cost_price || BigDecimal.new(0)) * i.quantity}
end

#descriptionObject



23
24
25
# File 'app/models/spina/shop/product_bundle.rb', line 23

def description
  short_description
end

#in_stock?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/spina/shop/product_bundle.rb', line 39

def in_stock?
  stock_level > 0
end

#original_priceObject



31
32
33
# File 'app/models/spina/shop/product_bundle.rb', line 31

def original_price
  bundled_products.inject(BigDecimal(0)){|t, i| t + i.product.price * i.quantity}
end

#price_for_order(order) ⇒ Object

Calculate the price based on this order



19
20
21
# File 'app/models/spina/shop/product_bundle.rb', line 19

def price_for_order(order)
  price
end

#short_descriptionObject



27
28
29
# File 'app/models/spina/shop/product_bundle.rb', line 27

def short_description
  name
end

#stock_levelObject



35
36
37
# File 'app/models/spina/shop/product_bundle.rb', line 35

def stock_level
  bundled_products.map{|b| (b.product.stock_level / b.quantity).floor}.min
end

#weightObject



43
44
45
# File 'app/models/spina/shop/product_bundle.rb', line 43

def weight
  bundled_products.inject(BigDecimal(0)){|t, i| t + (i.product.weight || BigDecimal.new(0)) * i.quantity}
end