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.
63 64 65 |
# File 'app/models/spree/line_item.rb', line 63 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.
45 46 47 48 49 50 51 |
# File 'app/models/spree/line_item.rb', line 45 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.
55 56 57 58 59 |
# File 'app/models/spree/line_item.rb', line 55 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.
70 71 72 |
# File 'app/models/spree/line_item.rb', line 70 def discounted_amount amount + promo_total end |
#discounted_money ⇒ Spree::Money
Returns the amount of this line item, taking into consideration line item promotions.
76 77 78 |
# File 'app/models/spree/line_item.rb', line 76 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.
82 83 84 |
# File 'app/models/spree/line_item.rb', line 82 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.
113 114 115 |
# File 'app/models/spree/line_item.rb', line 113 def insufficient_stock? !sufficient_stock? end |
#invalid_quantity_check ⇒ Object
Sets the quantity to zero if it is nil or less than zero.
101 102 103 |
# File 'app/models/spree/line_item.rb', line 101 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.
94 95 96 |
# File 'app/models/spree/line_item.rb', line 94 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/models/spree/line_item.rb', line 135 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.
120 121 122 |
# File 'app/models/spree/line_item.rb', line 120 def product variant.product end |
#single_money ⇒ Spree::Money Also known as: single_display_amount
Returns the price of this line item.
88 89 90 |
# File 'app/models/spree/line_item.rb', line 88 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.
107 108 109 |
# File 'app/models/spree/line_item.rb', line 107 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.
127 128 129 |
# File 'app/models/spree/line_item.rb', line 127 def variant Spree::Variant.unscoped { super } end |