Class: Effective::OrderItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/order_item.rb

Instance Method Summary collapse

Instance Method Details

#price=(value) ⇒ Object



56
57
58
59
60
61
62
# File 'app/models/effective/order_item.rb', line 56

def price=(value)
  if value.kind_of?(Integer)
    super
  else
    raise 'expected price to be an Integer representing the number of cents.'
  end
end

#purchased_download_urlObject



32
33
34
# File 'app/models/effective/order_item.rb', line 32

def purchased_download_url
  purchasable&.purchased_download_url
end

#quantityObject



40
41
42
# File 'app/models/effective/order_item.rb', line 40

def quantity
  self[:quantity] || 1
end

#subtotalObject



36
37
38
# File 'app/models/effective/order_item.rb', line 36

def subtotal
  price * quantity
end

#taxObject



44
45
46
47
48
# File 'app/models/effective/order_item.rb', line 44

def tax
  return 0 if tax_exempt?
  raise 'parent Effective::Order must have a tax_rate to compute order item tax' unless order.try(:tax_rate).present?
  (subtotal * order.tax_rate / 100.0).round(0).to_i
end

#to_sObject



28
29
30
# File 'app/models/effective/order_item.rb', line 28

def to_s
  ((quantity || 0) > 1 ? "#{quantity}x #{name}" : name) || 'order item'
end

#totalObject



50
51
52
53
54
# File 'app/models/effective/order_item.rb', line 50

def total
  return subtotal if tax_exempt?
  raise 'parent Effective::Order must have a tax_rate to compute order item total' unless order.try(:tax_rate).present?
  subtotal + tax
end