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 permenent 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.
Defined Under Namespace
Classes: CurrencyMismatch
Instance Attribute Summary collapse
-
#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.
- #currency=(_currency) ⇒ Object
-
#discounted_amount ⇒ BigDecimal
The amount of this line item, taking into consideration line item promotions.
-
#final_amount ⇒ BigDecimal
(also: #total)
The amount of this line item, taking into consideration all its adjustments.
-
#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.
-
#pre_tax_amount ⇒ BigDecimal
The amount of this line item before included tax.
- #pricing_options ⇒ Object
-
#sufficient_stock? ⇒ Boolean
True when it is possible to supply the required quantity of stock of this line item’s variant.
Methods included from DisplayMoney
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
Methods included from Preferences::Preferable
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Attribute Details
#target_shipment ⇒ Object
Returns the value of attribute target_shipment.
43 44 45 |
# File 'app/models/spree/line_item.rb', line 43 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.
50 51 52 |
# File 'app/models/spree/line_item.rb', line 50 def amount price * quantity end |
#currency=(_currency) ⇒ Object
137 138 139 140 141 |
# File 'app/models/spree/line_item.rb', line 137 def currency=(_currency) Spree::Deprecation.warn 'Spree::LineItem#currency= is deprecated ' \ 'and will take no effect.', caller end |
#discounted_amount ⇒ BigDecimal
Returns the amount of this line item, taking into consideration line item promotions.
57 58 59 |
# File 'app/models/spree/line_item.rb', line 57 def discounted_amount amount + promo_total end |
#final_amount ⇒ BigDecimal Also known as: total
Returns the amount of this line item, taking into consideration all its adjustments.
63 64 65 |
# File 'app/models/spree/line_item.rb', line 63 def final_amount amount + adjustment_total end |
#insufficient_stock? ⇒ Boolean
Returns true when it is not possible to supply the required quantity of stock of this line item’s variant.
110 111 112 |
# File 'app/models/spree/line_item.rb', line 110 def insufficient_stock? !sufficient_stock? end |
#money_price=(money) ⇒ Object
Sets price from a ‘Spree::Money` object
92 93 94 95 96 97 98 99 100 |
# File 'app/models/spree/line_item.rb', line 92 def money_price=(money) if !money self.price = nil elsif money.currency.iso_code != currency raise CurrencyMismatch, "Line item price currency must match order currency!" else 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.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/models/spree/line_item.rb', line 119 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.price_for() end end |
#pre_tax_amount ⇒ BigDecimal
just like ‘amount`, this does not include any additional tax
Returns the amount of this line item before included tax.
70 71 72 |
# File 'app/models/spree/line_item.rb', line 70 def pre_tax_amount discounted_amount - included_tax_total end |
#pricing_options ⇒ Object
133 134 135 |
# File 'app/models/spree/line_item.rb', line 133 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.
104 105 106 |
# File 'app/models/spree/line_item.rb', line 104 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |