Class: Spina::Shop::ProductBundle
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Shop::ProductBundle
- Defined in:
- app/models/spina/shop/product_bundle.rb
Instance Method Summary collapse
- #cost_price ⇒ Object
- #description ⇒ Object
- #in_stock? ⇒ Boolean
- #original_price ⇒ Object
-
#price_for_order(order) ⇒ Object
Calculate the price based on this order.
- #short_description ⇒ Object
- #stock_level ⇒ Object
- #weight ⇒ Object
Instance Method Details
#cost_price ⇒ Object
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 |
#description ⇒ Object
23 24 25 |
# File 'app/models/spina/shop/product_bundle.rb', line 23 def description short_description end |
#in_stock? ⇒ Boolean
39 40 41 |
# File 'app/models/spina/shop/product_bundle.rb', line 39 def in_stock? stock_level > 0 end |
#original_price ⇒ Object
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_description ⇒ Object
27 28 29 |
# File 'app/models/spina/shop/product_bundle.rb', line 27 def short_description name end |
#stock_level ⇒ Object
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 |
#weight ⇒ Object
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 |