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
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.
39 40 41 |
# File 'app/models/spree/line_item.rb', line 39 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.
46 47 48 |
# File 'app/models/spree/line_item.rb', line 46 def amount price * quantity end |
#discounted_amount ⇒ BigDecimal
Returns the amount of this line item, taking into consideration line item promotions.
53 54 55 |
# File 'app/models/spree/line_item.rb', line 53 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.
59 60 61 |
# File 'app/models/spree/line_item.rb', line 59 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.
100 101 102 |
# File 'app/models/spree/line_item.rb', line 100 def insufficient_stock? !sufficient_stock? end |
#money_price=(money) ⇒ Object
Sets price and currency from a ‘Spree::Money` object
87 88 89 90 |
# File 'app/models/spree/line_item.rb', line 87 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.
109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/spree/line_item.rb', line 109 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.
66 67 68 |
# File 'app/models/spree/line_item.rb', line 66 def pre_tax_amount discounted_amount - included_tax_total end |
#pricing_options ⇒ Object
120 121 122 |
# File 'app/models/spree/line_item.rb', line 120 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.
37 |
# File 'app/models/spree/line_item.rb', line 37 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.
94 95 96 |
# File 'app/models/spree/line_item.rb', line 94 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |