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



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

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_url ⇒ Object



30
31
32
# File 'app/models/effective/order_item.rb', line 30

def purchased_download_url
  purchasable&.purchased_download_url
end

#quantity ⇒ Object



38
39
40
# File 'app/models/effective/order_item.rb', line 38

def quantity
  self[:quantity] || 1
end

#subtotal ⇒ Object



34
35
36
# File 'app/models/effective/order_item.rb', line 34

def subtotal
  price * quantity
end

#tax ⇒ Object



42
43
44
45
46
# File 'app/models/effective/order_item.rb', line 42

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_s ⇒ Object



26
27
28
# File 'app/models/effective/order_item.rb', line 26

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

#total ⇒ Object



48
49
50
51
52
# File 'app/models/effective/order_item.rb', line 48

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