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

page, spree_base_scopes

Methods included from Preferences::Preferable

#clear_preferences, #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

#amountObject Also known as: subtotal



68
69
70
# File 'app/models/spree/line_item.rb', line 68

def amount
  price * quantity
end

#copy_priceObject



44
45
46
47
48
49
50
# File 'app/models/spree/line_item.rb', line 44

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



56
57
58
59
60
# File 'app/models/spree/line_item.rb', line 56

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

#final_amountObject Also known as: total



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

def final_amount
  amount + adjustment_total
end

#insufficient_stock?Boolean

Returns:

  • (Boolean)


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

def insufficient_stock?
  !sufficient_stock?
end

#invalid_quantity_checkObject



88
89
90
91
# File 'app/models/spree/line_item.rb', line 88

def invalid_quantity_check
  warn "`invalid_quantity_check` is deprecated. Use private `ensure_valid_quantity` instead."
  ensure_valid_quantity
end

#options=(options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'app/models/spree/line_item.rb', line 101

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)


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

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

#taxable_amountObject Also known as: discounted_amount



74
75
76
# File 'app/models/spree/line_item.rb', line 74

def taxable_amount
  amount + taxable_adjustment_total
end

#update_priceObject



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

def update_price
  self.price = variant.price_including_vat_for(tax_zone: tax_zone)
end

#variantObject

Remove variant default_scope ‘deleted_at: nil`



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

def variant
  Spree::Variant.unscoped { super }
end