Class: Spree::LineItem
- Extended by:
- DisplayMoney
- 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
-
#amount ⇒ BigDecimal
(also: #subtotal)
The amount of this line item, which is the line item’s price multiplied by its quantity.
-
#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 and currency 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
-
#product ⇒ Spree::Product?
The product associated with this line item, if there is one.
-
#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
#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.
40 41 42 |
# File 'app/models/spree/line_item.rb', line 40 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.
47 48 49 |
# File 'app/models/spree/line_item.rb', line 47 def amount price * quantity end |
#discounted_amount ⇒ BigDecimal
Returns the amount of this line item, taking into consideration line item promotions.
54 55 56 |
# File 'app/models/spree/line_item.rb', line 54 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.
60 61 62 |
# File 'app/models/spree/line_item.rb', line 60 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.
101 102 103 |
# File 'app/models/spree/line_item.rb', line 101 def insufficient_stock? !sufficient_stock? end |
#money_price=(money) ⇒ Object
Sets price and currency from a ‘Spree::Money` object
88 89 90 91 |
# File 'app/models/spree/line_item.rb', line 88 def money_price=(money) self.price = money.to_d self.currency = money.currency.iso_code end |
#options=(options = {}) ⇒ Object
Sets options on the line item and updates the price.
The options can be arbitrary attributes on the LineItem.
110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/spree/line_item.rb', line 110 def ( = {}) return unless .present? assign_attributes # There's no need to call a pricer if we'll set the price directly. 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.
67 68 69 |
# File 'app/models/spree/line_item.rb', line 67 def pre_tax_amount discounted_amount - included_tax_total end |
#pricing_options ⇒ Object
121 122 123 |
# File 'app/models/spree/line_item.rb', line 121 def Spree::Config..from_line_item(self) end |
#product ⇒ Spree::Product?
This will return the product even if it has been deleted.
Returns the product associated with this line item, if there is one.
38 |
# File 'app/models/spree/line_item.rb', line 38 delegate :product, to: :variant |
#sufficient_stock? ⇒ Boolean
Returns true when it is possible to supply the required quantity of stock of this line item’s variant.
95 96 97 |
# File 'app/models/spree/line_item.rb', line 95 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |