Class: Spree::LineItem
- Extended by:
- DisplayMoney
- Defined in:
- app/models/spree/line_item.rb
Overview
Variants placed in the Order at a particular price.
‘Spree::LineItem` is an ActiveRecord model which records which `Spree::Variant` a customer has chosen to place in their order. It also acts as the permanent record of the customer’s order by recording relevant price, taxation, and inventory concerns. Line items can also have adjustments placed on them as part of the promotion system.
Instance Attribute Summary collapse
-
#price_currency ⇒ Object
Returns the value of attribute price_currency.
-
#target_shipment ⇒ Object
Returns the value of attribute target_shipment.
Instance Method Summary collapse
-
#amount ⇒ BigDecimal
(also: #subtotal)
The amount of this line item, which is the line item’s price multiplied by its quantity.
-
#insufficient_stock? ⇒ Boolean
True when it is not possible to supply the required quantity of stock of this line item’s variant.
-
#money_price=(money) ⇒ Object
Sets price from a ‘Spree::Money` object.
-
#options=(options = {}) ⇒ Object
Sets options on the line item and updates the price.
- #pricing_options ⇒ Object
-
#sufficient_stock? ⇒ Boolean
True when it is possible to supply the required quantity of stock of this line item’s variant.
-
#total ⇒ BigDecimal
The amount of this line item, taking into consideration all its adjustments.
-
#total_before_tax ⇒ BigDecimal
The amount of this item, taking into consideration all non-tax adjustments.
-
#total_excluding_vat ⇒ BigDecimal
The amount of this line item before VAT tax.
Methods included from DisplayMoney
Methods inherited from Base
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Attribute Details
#price_currency ⇒ Object
Returns the value of attribute price_currency.
41 42 43 |
# File 'app/models/spree/line_item.rb', line 41 def price_currency @price_currency end |
#target_shipment ⇒ Object
Returns the value of attribute target_shipment.
41 42 43 |
# File 'app/models/spree/line_item.rb', line 41 def target_shipment @target_shipment end |
Instance Method Details
#amount ⇒ BigDecimal Also known as: subtotal
Returns the amount of this line item, which is the line item’s price multiplied by its quantity.
48 49 50 |
# File 'app/models/spree/line_item.rb', line 48 def amount price * quantity end |
#insufficient_stock? ⇒ Boolean
Returns true when it is not possible to supply the required quantity of stock of this line item’s variant.
104 105 106 |
# File 'app/models/spree/line_item.rb', line 104 def insufficient_stock? !sufficient_stock? end |
#money_price=(money) ⇒ Object
Sets price from a ‘Spree::Money` object
87 88 89 90 91 92 93 94 |
# File 'app/models/spree/line_item.rb', line 87 def money_price=(money) if !money self.price = nil else self.price_currency = money.currency.iso_code self.price = money.to_d end end |
#options=(options = {}) ⇒ Object
Sets options on the line item and updates the price.
The options can be arbitrary attributes on the LineItem.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/models/spree/line_item.rb', line 113 def ( = {}) return unless .present? assign_attributes # When price is part of the options we are not going to fetch # it from the variant. Please note that this always allows to set # a price for this line item, even if there is no existing price # for the associated line item in the order currency. unless .key?(:price) || .key?('price') self.money_price = variant.()&.money end end |
#pricing_options ⇒ Object
127 128 129 |
# File 'app/models/spree/line_item.rb', line 127 def Spree::Config..from_line_item(self) end |
#sufficient_stock? ⇒ Boolean
Returns true when it is possible to supply the required quantity of stock of this line item’s variant.
98 99 100 |
# File 'app/models/spree/line_item.rb', line 98 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |
#total ⇒ BigDecimal
Returns the amount of this line item, taking into consideration all its adjustments.
55 56 57 |
# File 'app/models/spree/line_item.rb', line 55 def total amount + adjustment_total end |
#total_before_tax ⇒ BigDecimal
Returns the amount of this item, taking into consideration all non-tax adjustments.
61 62 63 |
# File 'app/models/spree/line_item.rb', line 61 def total_before_tax amount + adjustments.reject(&:tax?).sum(&:amount) end |
#total_excluding_vat ⇒ BigDecimal
just like ‘amount`, this does not include any additional tax
Returns the amount of this line item before VAT tax.
67 68 69 |
# File 'app/models/spree/line_item.rb', line 67 def total_excluding_vat total_before_tax - included_tax_total end |