Class: Spree::LineItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

page

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



36
37
38
# File 'app/models/spree/line_item.rb', line 36

def target_shipment
  @target_shipment
end

Instance Method Details

#amountObject Also known as: subtotal



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

def amount
  price * quantity
end

#copy_priceObject



38
39
40
41
42
43
44
# File 'app/models/spree/line_item.rb', line 38

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_categoryObject



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

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

#discounted_amountObject



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

def discounted_amount
  amount + promo_total
end

#discounted_moneyObject



61
62
63
# File 'app/models/spree/line_item.rb', line 61

def discounted_money
  Spree::Money.new(discounted_amount, { currency: currency })
end

#final_amountObject Also known as: total



65
66
67
# File 'app/models/spree/line_item.rb', line 65

def final_amount
  amount + adjustment_total
end

#insufficient_stock?Boolean

Returns:

  • (Boolean)


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

def insufficient_stock?
  !sufficient_stock?
end

#invalid_quantity_checkObject



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

def invalid_quantity_check
  self.quantity = 0 if quantity.nil? || quantity < 0
end

#moneyObject Also known as: display_total, display_amount



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

def money
  Spree::Money.new(amount, { currency: currency })
end

#options=(options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/spree/line_item.rb', line 103

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)

  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

#productObject

Remove product default_scope `deleted_at: nil`



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

def product
  variant.product
end

#single_moneyObject Also known as: single_display_amount



70
71
72
# File 'app/models/spree/line_item.rb', line 70

def single_money
  Spree::Money.new(price, { currency: currency })
end

#sufficient_stock?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/spree/line_item.rb', line 85

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

#variantObject

Remove variant default_scope `deleted_at: nil`



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

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