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



55
56
57
# File 'app/models/spree/line_item.rb', line 55

def amount
  price * quantity
end

#copy_priceObject



41
42
43
44
45
46
47
# File 'app/models/spree/line_item.rb', line 41

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



49
50
51
52
53
# File 'app/models/spree/line_item.rb', line 49

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

#discounted_amountObject



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

def discounted_amount
  amount + promo_total
end

#discounted_moneyObject



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

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

#final_amountObject Also known as: total



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

def final_amount
  amount + adjustment_total
end

#insufficient_stock?Boolean

Returns:

  • (Boolean)


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

def insufficient_stock?
  !sufficient_stock?
end

#invalid_quantity_checkObject



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

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

#moneyObject Also known as: display_total, display_amount



78
79
80
# File 'app/models/spree/line_item.rb', line 78

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

#options=(options = {}) ⇒ Object



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

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`



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

def product
  variant.product
end

#single_moneyObject Also known as: single_display_amount



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

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

#sufficient_stock?Boolean

Returns:

  • (Boolean)


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

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

#variantObject

Remove variant default_scope ‘deleted_at: nil`



102
103
104
# File 'app/models/spree/line_item.rb', line 102

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