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
- #check_nil_fields ⇒ Object
- #copy ⇒ Object
- #quantity_in_stock ⇒ Object
- #subtotal ⇒ Object
- #title ⇒ Object
-
#update_price ⇒ Object
Methods.
Instance Method Details
#as_json(options = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'app/models/caboose/line_item.rb', line 74 def as_json(={}) self.attributes.merge({ :variant => self.variant, :title => self.title }) end |
#check_nil_fields ⇒ Object
54 55 56 |
# File 'app/models/caboose/line_item.rb', line 54 def check_nil_fields self.price = 0.00 if self.price.nil? end |
#copy ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/caboose/line_item.rb', line 85 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
81 82 83 |
# File 'app/models/caboose/line_item.rb', line 81 def subtotal return self.quantity * self.price end |
#title ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/models/caboose/line_item.rb', line 66 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
62 63 64 |
# File 'app/models/caboose/line_item.rb', line 62 def update_price self.price = self.variant.price * self.quantity end |