Class: Spree::LineItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::LineItem
- Defined in:
- app/models/spree/line_item.rb
Instance Attribute Summary collapse
-
#target_shipment ⇒ Object
Returns the value of attribute target_shipment.
Instance Method Summary collapse
- #adjust_quantity ⇒ Object
- #amount ⇒ Object (also: #total)
- #assign_stock_changes_to=(shipment) ⇒ Object
- #copy_price ⇒ Object
- #copy_tax_category ⇒ Object
- #decrement_quantity ⇒ Object
- #increment_quantity ⇒ Object
- #insufficient_stock? ⇒ Boolean
- #money ⇒ Object (also: #display_total, #display_amount)
-
#product ⇒ Object
Remove product default_scope ‘deleted_at: nil`.
- #single_money ⇒ Object (also: #single_display_amount)
- #sufficient_stock? ⇒ Boolean
-
#variant ⇒ Object
Remove variant default_scope ‘deleted_at: nil`.
Instance Attribute Details
#target_shipment ⇒ Object
Returns the value of attribute target_shipment.
31 32 33 |
# File 'app/models/spree/line_item.rb', line 31 def target_shipment @target_shipment end |
Instance Method Details
#adjust_quantity ⇒ Object
73 74 75 |
# File 'app/models/spree/line_item.rb', line 73 def adjust_quantity self.quantity = 0 if quantity.nil? || quantity < 0 end |
#amount ⇒ Object Also known as: total
57 58 59 |
# File 'app/models/spree/line_item.rb', line 57 def amount price * quantity end |
#assign_stock_changes_to=(shipment) ⇒ Object
85 86 87 |
# File 'app/models/spree/line_item.rb', line 85 def assign_stock_changes_to=(shipment) @preferred_shipment = shipment end |
#copy_price ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/spree/line_item.rb', line 33 def copy_price if variant self.price = variant.price if price.nil? self.cost_price = variant.cost_price if cost_price.nil? self.currency = variant.currency if currency.nil? end end |
#copy_tax_category ⇒ Object
41 42 43 44 45 |
# File 'app/models/spree/line_item.rb', line 41 def copy_tax_category if variant self.tax_category = variant.product.tax_category end end |
#decrement_quantity ⇒ Object
52 53 54 55 |
# File 'app/models/spree/line_item.rb', line 52 def decrement_quantity ActiveSupport::Deprecation.warn("[SPREE] Spree::LineItem#decrement_quantity will be deprecated in Spree 2.1, please use quantity.decrement! instead.") self.quantity.decrement! end |
#increment_quantity ⇒ Object
47 48 49 50 |
# File 'app/models/spree/line_item.rb', line 47 def increment_quantity ActiveSupport::Deprecation.warn("[SPREE] Spree::LineItem#increment_quantity will be deprecated in Spree 2.1, please use quantity.increment! instead.") self.quantity.increment! end |
#insufficient_stock? ⇒ Boolean
81 82 83 |
# File 'app/models/spree/line_item.rb', line 81 def insufficient_stock? !sufficient_stock? end |
#money ⇒ Object Also known as: display_total, display_amount
67 68 69 |
# File 'app/models/spree/line_item.rb', line 67 def money Spree::Money.new(amount, { currency: currency }) end |
#product ⇒ Object
Remove product default_scope ‘deleted_at: nil`
90 91 92 |
# File 'app/models/spree/line_item.rb', line 90 def product variant.product end |
#single_money ⇒ Object Also known as: single_display_amount
62 63 64 |
# File 'app/models/spree/line_item.rb', line 62 def single_money Spree::Money.new(price, { currency: currency }) end |
#sufficient_stock? ⇒ Boolean
77 78 79 |
# File 'app/models/spree/line_item.rb', line 77 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |