Class: LineItem
- Defined in:
- app/models/line_item.rb
Instance Method Summary collapse
- #adjust_quantity ⇒ Object
- #decrement_quantity ⇒ Object
- #increment_quantity ⇒ Object
- #total ⇒ Object (also: #amount)
- #validate ⇒ Object
Instance Method Details
#adjust_quantity ⇒ Object
39 40 41 |
# File 'app/models/line_item.rb', line 39 def adjust_quantity self.quantity = 0 if self.quantity.nil? || self.quantity < 0 end |
#decrement_quantity ⇒ Object
30 31 32 |
# File 'app/models/line_item.rb', line 30 def decrement_quantity self.quantity -= 1 end |
#increment_quantity ⇒ Object
26 27 28 |
# File 'app/models/line_item.rb', line 26 def increment_quantity self.quantity += 1 end |
#total ⇒ Object Also known as: amount
34 35 36 |
# File 'app/models/line_item.rb', line 34 def total self.price * self.quantity end |
#validate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/line_item.rb', line 14 def validate unless quantity && quantity >= 0 errors.add(:quantity, "must be a non-negative value") end # avoid reload of order.inventory_units by using direct lookup unless Spree::Config[:allow_backorders] || order && InventoryUnit.order_id_equals(order).first.present? || variant && quantity <= variant.on_hand errors.add(:quantity, " is too large-- stock on hand cannot cover requested quantity!") end end |