Class: Effective::OrderItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::OrderItem
- Defined in:
- app/models/effective/order_item.rb
Instance Method Summary collapse
- #price=(value) ⇒ Object
- #purchased_download_url ⇒ Object
-
#qb_item_name ⇒ Object
first or build.
- #quantity ⇒ Object
- #subtotal ⇒ Object
- #tax ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Instance Method Details
#price=(value) ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/models/effective/order_item.rb', line 60 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
36 37 38 |
# File 'app/models/effective/order_item.rb', line 36 def purchased_download_url purchasable&.purchased_download_url end |
#qb_item_name ⇒ Object
first or build
69 70 71 72 |
# File 'app/models/effective/order_item.rb', line 69 def qb_item_name raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync) (qb_order_item || build_qb_order_item(name: purchasable.qb_item_name)).name end |
#quantity ⇒ Object
44 45 46 |
# File 'app/models/effective/order_item.rb', line 44 def quantity self[:quantity] || 1 end |
#subtotal ⇒ Object
40 41 42 |
# File 'app/models/effective/order_item.rb', line 40 def subtotal price * quantity end |
#tax ⇒ Object
48 49 50 51 52 |
# File 'app/models/effective/order_item.rb', line 48 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
32 33 34 |
# File 'app/models/effective/order_item.rb', line 32 def to_s ((quantity || 0) > 1 ? "#{quantity}x #{name}" : name) || 'order item' end |
#total ⇒ Object
54 55 56 57 58 |
# File 'app/models/effective/order_item.rb', line 54 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 |