Class: Spree::LineItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::LineItem
- Defined in:
- app/models/spree/line_item.rb
Instance Method Summary collapse
- #adjust_quantity ⇒ Object
- #amount ⇒ Object (also: #total)
- #copy_price ⇒ Object
- #decrement_quantity ⇒ Object
- #increment_quantity ⇒ Object
- #insufficient_stock? ⇒ Boolean
- #money ⇒ Object (also: #display_total, #display_amount)
- #single_money ⇒ Object (also: #single_display_amount)
- #sufficient_stock? ⇒ Boolean
Instance Method Details
#adjust_quantity ⇒ Object
57 58 59 |
# File 'app/models/spree/line_item.rb', line 57 def adjust_quantity self.quantity = 0 if quantity.nil? || quantity < 0 end |
#amount ⇒ Object Also known as: total
41 42 43 |
# File 'app/models/spree/line_item.rb', line 41 def amount price * quantity end |
#copy_price ⇒ Object
26 27 28 29 30 31 |
# File 'app/models/spree/line_item.rb', line 26 def copy_price if variant self.price = variant.price if price.nil? self.currency = variant.currency if currency.nil? end end |
#decrement_quantity ⇒ Object
37 38 39 |
# File 'app/models/spree/line_item.rb', line 37 def decrement_quantity self.quantity -= 1 end |
#increment_quantity ⇒ Object
33 34 35 |
# File 'app/models/spree/line_item.rb', line 33 def increment_quantity self.quantity += 1 end |
#insufficient_stock? ⇒ Boolean
70 71 72 |
# File 'app/models/spree/line_item.rb', line 70 def insufficient_stock? !sufficient_stock? end |
#money ⇒ Object Also known as: display_total, display_amount
51 52 53 |
# File 'app/models/spree/line_item.rb', line 51 def money Spree::Money.new(amount, { :currency => currency }) end |
#single_money ⇒ Object Also known as: single_display_amount
46 47 48 |
# File 'app/models/spree/line_item.rb', line 46 def single_money Spree::Money.new(price, { :currency => currency }) end |
#sufficient_stock? ⇒ Boolean
61 62 63 64 65 66 67 68 |
# File 'app/models/spree/line_item.rb', line 61 def sufficient_stock? return true if Spree::Config[:allow_backorders] if new_record? || !order.completed? variant.on_hand >= quantity else variant.on_hand >= (quantity - self.changed_attributes['quantity'].to_i) end end |