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


28
29
30
# File 'app/models/spree/line_item.rb', line 28

def target_shipment
  @target_shipment
end

Instance Method Details

#adjust_quantityObject


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

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

#amountObject Also known as: total


44
45
46
# File 'app/models/spree/line_item.rb', line 44

def amount
  price * quantity
end

#assign_stock_changes_to=(shipment) ⇒ Object


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

def assign_stock_changes_to=(shipment)
  @preferred_shipment = shipment
end

#copy_priceObject


30
31
32
33
34
35
36
# File 'app/models/spree/line_item.rb', line 30

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


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

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

#insufficient_stock?Boolean


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

def insufficient_stock?
  !sufficient_stock?
end

#moneyObject Also known as: display_total, display_amount


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

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

#productObject

Remove product default_scope `deleted_at: nil`


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

def product
  variant.product
end

#single_moneyObject Also known as: single_display_amount


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

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

#sufficient_stock?Boolean


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

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

#variantObject

Remove variant default_scope `deleted_at: nil`


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

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