Class: Spree::LineItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_shipmentObject

Returns the value of attribute target_shipment


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

def target_shipment
  @target_shipment
end

Instance Method Details

#adjust_quantityObject


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

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

#amountObject Also known as: subtotal


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

def amount
  price * quantity
end

#assign_stock_changes_to=(shipment) ⇒ Object


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

def assign_stock_changes_to=(shipment)
  @preferred_shipment = shipment
end

#copy_priceObject


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

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


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

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

#discounted_amountObject


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

def discounted_amount
  amount + promo_total
end

#final_amountObject Also known as: total


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

def final_amount
  amount + adjustment_total.to_f
end

#insufficient_stock?Boolean

Returns:

  • (Boolean)

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

def insufficient_stock?
  !sufficient_stock?
end

#moneyObject Also known as: display_total, display_amount


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

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

#productObject

Remove product default_scope `deleted_at: nil`


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

def product
  variant.product
end

#single_moneyObject Also known as: single_display_amount


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

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

#sufficient_stock?Boolean

Returns:

  • (Boolean)

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

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

#variantObject

Remove variant default_scope `deleted_at: nil`


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

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