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
- #copy ⇒ Object
- #quantity_in_stock ⇒ Object
- #subtotal ⇒ Object
- #title ⇒ Object
-
#update_price ⇒ Object
Methods.
Instance Method Details
#as_json(options = {}) ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/caboose/line_item.rb', line 69 def as_json(={}) self.attributes.merge({ :variant => self.variant, :title => self.title }) end |
#copy ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/caboose/line_item.rb', line 80 def copy LineItem.new( :variant_id => self.variant_id , :quantity => self.quantity , :price => self.price , :notes => self.notes , :order_id => self.order_id , :status => self.status , :custom1 => self.custom1 , :custom2 => self.custom2 , :custom3 => self.custom3 ) end |
#quantity_in_stock ⇒ Object
42 43 44 |
# File 'app/models/caboose/line_item.rb', line 42 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
61 62 63 64 65 66 67 |
# File 'app/models/caboose/line_item.rb', line 61 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
57 58 59 |
# File 'app/models/caboose/line_item.rb', line 57 def update_price self.price = self.variant.price * self.quantity end |