Class: Spree::LineItem
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Spree::LineItem
show all
- Defined in:
- app/models/spree/line_item.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
page
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Attribute Details
#target_shipment ⇒ Object
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
#adjust_quantity ⇒ Object
77
78
79
|
# File 'app/models/spree/line_item.rb', line 77
def adjust_quantity
self.quantity = 0 if quantity.nil? || quantity < 0
end
|
#amount ⇒ Object
Also known as:
subtotal
52
53
54
|
# File 'app/models/spree/line_item.rb', line 52
def amount
price * quantity
end
|
#copy_price ⇒ Object
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_category ⇒ Object
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_amount ⇒ Object
57
58
59
|
# File 'app/models/spree/line_item.rb', line 57
def discounted_amount
amount + promo_total
end
|
#final_amount ⇒ Object
Also known as:
total
61
62
63
|
# File 'app/models/spree/line_item.rb', line 61
def final_amount
amount + adjustment_total.to_f
end
|
#insufficient_stock? ⇒ Boolean
85
86
87
|
# File 'app/models/spree/line_item.rb', line 85
def insufficient_stock?
!sufficient_stock?
end
|
#money ⇒ Object
Also known as:
display_total, display_amount
71
72
73
|
# File 'app/models/spree/line_item.rb', line 71
def money
Spree::Money.new(amount, { currency: currency })
end
|
#product ⇒ Object
Remove product default_scope ‘deleted_at: nil`
90
91
92
|
# File 'app/models/spree/line_item.rb', line 90
def product
variant.product
end
|
#single_money ⇒ Object
Also known as:
single_display_amount
66
67
68
|
# File 'app/models/spree/line_item.rb', line 66
def single_money
Spree::Money.new(price, { currency: currency })
end
|
#sufficient_stock? ⇒ Boolean
81
82
83
|
# File 'app/models/spree/line_item.rb', line 81
def sufficient_stock?
Stock::Quantifier.new(variant).can_supply? quantity
end
|
#variant ⇒ Object
Remove variant default_scope ‘deleted_at: nil`
95
96
97
|
# File 'app/models/spree/line_item.rb', line 95
def variant
Spree::Variant.unscoped { super }
end
|