Class: 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
-
#amount ⇒ BigDecimal
(also: #subtotal)
The amount of this line item, which is the line item’s price multiplied by its quantity.
-
#copy_price ⇒ Object
Sets this line item’s price, cost price, and currency from this line item’s variant if they are nil and a variant is present.
-
#copy_tax_category ⇒ Object
Sets this line item’s tax category from this line item’s variant if a variant is present.
-
#discounted_amount ⇒ BigDecimal
The amount of this line item, taking into consideration line item promotions.
-
#discounted_money ⇒ Spree::Money
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.
-
#invalid_quantity_check ⇒ Object
Sets the quantity to zero if it is nil or less than zero.
-
#money ⇒ Spree::Moeny
(also: #display_total, #display_amount)
The amount of this line item.
-
#options=(options = {}) ⇒ Object
Sets the options on the line item according to the order’s currency or one passed in.
-
#product ⇒ Spree::Product?
The product associated with this line item, if there is one.
-
#single_money ⇒ Spree::Money
(also: #single_display_amount)
The price of this line item.
-
#sufficient_stock? ⇒ Boolean
True when it is possible to supply the required quantity of stock of this line item’s variant.
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.
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.
68 69 70 |
# File 'app/models/spree/line_item.rb', line 68 def amount price * quantity end |
#copy_price ⇒ Object
Sets this line item’s price, cost price, and currency from this line item’s variant if they are nil and a variant is present.
50 51 52 53 54 55 56 |
# File 'app/models/spree/line_item.rb', line 50 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
Sets this line item’s tax category from this line item’s variant if a variant is present.
60 61 62 63 64 |
# File 'app/models/spree/line_item.rb', line 60 def copy_tax_category if variant self.tax_category = variant.tax_category end end |
#discounted_amount ⇒ BigDecimal
Returns the amount of this line item, taking into consideration line item promotions.
75 76 77 |
# File 'app/models/spree/line_item.rb', line 75 def discounted_amount amount + promo_total end |
#discounted_money ⇒ Spree::Money
Returns the amount of this line item, taking into consideration line item promotions.
81 82 83 |
# File 'app/models/spree/line_item.rb', line 81 def discounted_money Spree::Money.new(discounted_amount, { currency: currency }) end |
#final_amount ⇒ BigDecimal Also known as: total
Returns the amount of this line item, taking into consideration all its adjustments.
87 88 89 |
# File 'app/models/spree/line_item.rb', line 87 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.
118 119 120 |
# File 'app/models/spree/line_item.rb', line 118 def insufficient_stock? !sufficient_stock? end |
#invalid_quantity_check ⇒ Object
Sets the quantity to zero if it is nil or less than zero.
106 107 108 |
# File 'app/models/spree/line_item.rb', line 106 def invalid_quantity_check self.quantity = 0 if quantity.nil? || quantity < 0 end |
#money ⇒ Spree::Moeny Also known as: display_total, display_amount
Returns the amount of this line item.
99 100 101 |
# File 'app/models/spree/line_item.rb', line 99 def money Spree::Money.new(amount, { currency: currency }) end |
#options=(options = {}) ⇒ Object
Sets the options on the line item according to the order’s currency or one passed in.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/spree/line_item.rb', line 126 def (={}) return unless .present? opts = .dup # we will be deleting from the hash, so leave the caller's copy intact currency = opts.delete(:currency) || order.try(:currency) if currency self.currency = currency self.price = variant.price_in(currency).amount + variant.price_modifier_amount_in(currency, opts) else self.price = variant.price + variant.price_modifier_amount(opts) end self.assign_attributes opts 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.
40 |
# File 'app/models/spree/line_item.rb', line 40 delegate :product, to: :variant |
#single_money ⇒ Spree::Money Also known as: single_display_amount
Returns the price of this line item.
93 94 95 |
# File 'app/models/spree/line_item.rb', line 93 def single_money Spree::Money.new(price, { currency: currency }) end |
#sufficient_stock? ⇒ Boolean
Returns true when it is possible to supply the required quantity of stock of this line item’s variant.
112 113 114 |
# File 'app/models/spree/line_item.rb', line 112 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |