Class: Caboose::LineItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::LineItem
- Defined in:
- app/models/caboose/line_item.rb
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #quantity_in_stock ⇒ Object
- #subtotal ⇒ Object
- #title ⇒ Object
-
#update_price ⇒ Object
Methods.
Instance Method Details
#as_json(options = {}) ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/models/caboose/line_item.rb', line 68 def as_json(={}) self.attributes.merge({ :variant => self.variant, :title => self.title, :product => { :images => self.variant.product.product_images } }) end |
#quantity_in_stock ⇒ Object
41 42 43 |
# File 'app/models/caboose/line_item.rb', line 41 def quantity_in_stock errors.add(:base, "There #{self.variant.quantity_in_stock > 1 ? 'are' : 'is'} only #{self.variant.quantity_in_stock} left in stock.") if self.variant.quantity_in_stock - self.quantity < 0 end |
#subtotal ⇒ Object
76 77 78 |
# File 'app/models/caboose/line_item.rb', line 76 def subtotal return self.quantity * self.price end |
#title ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/models/caboose/line_item.rb', line 60 def title if self.variant.product.variants.count > 1 "#{self.variant.product.title} - #{self.variant.title}" else self.variant.product.title end end |
#update_price ⇒ Object
Methods
56 57 58 |
# File 'app/models/caboose/line_item.rb', line 56 def update_price self.price = self.variant.price * self.quantity end |