Class: Spree::LineItem

Inherits:
Base
  • Object
show all
Extended by:
DisplayMoney
Defined in:
app/models/spree/line_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

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_shipmentObject

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

#amountBigDecimal Also known as: subtotal

Returns the amount of this line item, which is the line item’s price multiplied by its quantity.

Returns:

  • (BigDecimal)

    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_amountBigDecimal

Returns the amount of this line item, taking into consideration line item promotions.

Returns:

  • (BigDecimal)

    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_amountBigDecimal Also known as: total

Returns the amount of this line item, taking into consideration all its adjustments.

Returns:

  • (BigDecimal)

    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.

Returns:

  • (Boolean)

    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

Parameters:

  • money (Spree::Money)
    • the money object to obtain price and currency from



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.

Parameters:

  • options (Hash) (defaults to: {})

    options for this line item



109
110
111
112
113
114
115
116
117
118
# File 'app/models/spree/line_item.rb', line 109

def options=(options = {})
  return unless options.present?

  assign_attributes options

  # There's no need to call a pricer if we'll set the price directly.
  unless options.key?(:price) || options.key?('price')
    self.money_price = variant.price_for(pricing_options)
  end
end

#pre_tax_amountBigDecimal

Note:

just like ‘amount`, this does not include any additional tax

Returns the amount of this line item before included tax.

Returns:

  • (BigDecimal)

    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_optionsObject



120
121
122
# File 'app/models/spree/line_item.rb', line 120

def pricing_options
  Spree::Config.pricing_options_class.from_line_item(self)
end

#productSpree::Product?

Note:

This will return the product even if it has been deleted.

Returns the product associated with this line item, if there is one.

Returns:

  • (Spree::Product, nil)

    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.

Returns:

  • (Boolean)

    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