Class: CartItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CartItem
- Defined in:
- app/models/cart_item.rb
Instance Method Summary collapse
- #increment_quantity(increment) ⇒ Object
-
#price ⇒ Object
Total price.
- #pricef ⇒ Object
- #quantity=(quantity) ⇒ Object
- #remove_from_cart! ⇒ Object
- #shipping_weight ⇒ Object
-
#to_s ⇒ Object
needed for rails magic form_for stuff, so DO NOT change this to some debug/display value.
-
#unit_price ⇒ Object
Price per unit.
- #unit_pricef ⇒ Object
Instance Method Details
#increment_quantity(increment) ⇒ Object
7 8 9 |
# File 'app/models/cart_item.rb', line 7 def increment_quantity(increment) self.quantity += increment end |
#price ⇒ Object
Total price
32 |
# File 'app/models/cart_item.rb', line 32 def price ; self.product.price * self.quantity ; end |
#pricef ⇒ Object
33 |
# File 'app/models/cart_item.rb', line 33 def pricef ; Cart.format_price(self.price()) ; end |
#quantity=(quantity) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/models/cart_item.rb', line 11 def quantity=(quantity) if quantity < 1 self.remove_from_cart! else write_attribute(:quantity, quantity) end end |
#remove_from_cart! ⇒ Object
23 24 25 |
# File 'app/models/cart_item.rb', line 23 def remove_from_cart! self.destroy() end |
#shipping_weight ⇒ Object
19 20 21 |
# File 'app/models/cart_item.rb', line 19 def shipping_weight self.product.shipping_weight * self.quantity end |
#to_s ⇒ Object
needed for rails magic form_for stuff, so DO NOT change this to some debug/display value
36 37 38 |
# File 'app/models/cart_item.rb', line 36 def to_s self.product_id end |
#unit_price ⇒ Object
Price per unit
28 |
# File 'app/models/cart_item.rb', line 28 def unit_price ; self.product.price ; end |
#unit_pricef ⇒ Object
29 |
# File 'app/models/cart_item.rb', line 29 def unit_pricef ; Cart.format_price(self.unit_price()) ; end |