Class: Spree::LineItem

Inherits:
Base
  • Object
show all
Extended by:
DisplayMoney
Includes:
Metadata, Webhooks::HasWebhooks
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

belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Instance Attribute Details

#target_shipmentObject

Returns the value of attribute target_shipment.



53
54
55
# File 'app/models/spree/line_item.rb', line 53

def target_shipment
  @target_shipment
end

Instance Method Details

#amountObject Also known as: subtotal



92
93
94
# File 'app/models/spree/line_item.rb', line 92

def amount
  price * quantity
end

#copy_priceObject



62
63
64
65
66
67
68
# File 'app/models/spree/line_item.rb', line 62

def copy_price
  if variant
    update_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_categoryObject



80
81
82
# File 'app/models/spree/line_item.rb', line 80

def copy_tax_category
  self.tax_category = variant.tax_category if variant
end

#final_amountObject Also known as: total



105
106
107
# File 'app/models/spree/line_item.rb', line 105

def final_amount
  amount + adjustment_total
end

#insufficient_stock?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/spree/line_item.rb', line 116

def insufficient_stock?
  !sufficient_stock?
end

#options=(options = {}) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'app/models/spree/line_item.rb', line 120

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

  opts = options.dup # we will be deleting from the hash, so leave the caller's copy intact

  currency = opts.delete(:currency) || order.try(:currency)

  update_price_from_modifier(currency, opts)
  assign_attributes opts
end

#sufficient_stock?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'app/models/spree/line_item.rb', line 112

def sufficient_stock?
  Spree::Stock::Quantifier.new(variant).can_supply? quantity
end

#taxable_amountObject Also known as: discounted_amount



98
99
100
# File 'app/models/spree/line_item.rb', line 98

def taxable_amount
  amount + taxable_adjustment_total
end

#update_priceObject



70
71
72
73
74
75
76
77
78
# File 'app/models/spree/line_item.rb', line 70

def update_price
  currency_price = variant.price_in(order.currency)

  self.price = if currency_price.amount.present?
                 currency_price.price_including_vat_for(tax_zone: tax_zone)
               else
                 0
               end
end