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.
-
#variant ⇒ Spree::Variant?
The variant associated with this line item, if there is one.
Methods inherited from Base
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.
38 39 40 |
# File 'app/models/spree/line_item.rb', line 38 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.
60 61 62 |
# File 'app/models/spree/line_item.rb', line 60 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.
42 43 44 45 46 47 48 |
# File 'app/models/spree/line_item.rb', line 42 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.
52 53 54 55 56 |
# File 'app/models/spree/line_item.rb', line 52 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.
67 68 69 |
# File 'app/models/spree/line_item.rb', line 67 def discounted_amount amount + promo_total end |
#discounted_money ⇒ Spree::Money
Returns the amount of this line item, taking into consideration line item promotions.
73 74 75 |
# File 'app/models/spree/line_item.rb', line 73 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.
79 80 81 |
# File 'app/models/spree/line_item.rb', line 79 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 |
#invalid_quantity_check ⇒ Object
Sets the quantity to zero if it is nil or less than zero.
98 99 100 |
# File 'app/models/spree/line_item.rb', line 98 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.
91 92 93 |
# File 'app/models/spree/line_item.rb', line 91 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.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/spree/line_item.rb', line 132 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.
117 118 119 |
# File 'app/models/spree/line_item.rb', line 117 def product variant.product end |
#single_money ⇒ Spree::Money Also known as: single_display_amount
Returns the price of this line item.
85 86 87 |
# File 'app/models/spree/line_item.rb', line 85 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.
104 105 106 |
# File 'app/models/spree/line_item.rb', line 104 def sufficient_stock? Stock::Quantifier.new(variant).can_supply? quantity end |
#variant ⇒ Spree::Variant?
This will return the variant even if it has been deleted.
Returns the variant associated with this line item, if there is one.
124 125 126 |
# File 'app/models/spree/line_item.rb', line 124 def variant Spree::Variant.unscoped { super } end |