Class: Spina::Shop::Discount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Shop::Discount
- Includes:
- Preferable
- Defined in:
- app/models/spina/shop/discount.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #discount_for_order_item(order_item) ⇒ Object
- #inactive? ⇒ Boolean
- #order_item_eligible?(order_item) ⇒ Boolean
Instance Method Details
#active? ⇒ Boolean
18 19 20 |
# File 'app/models/spina/shop/discount.rb', line 18 def active? starts_at <= Date.today && (expires_at.blank? || expires_at >= Date.today) end |
#discount_for_order_item(order_item) ⇒ Object
32 33 34 35 36 |
# File 'app/models/spina/shop/discount.rb', line 32 def discount_for_order_item(order_item) return BigDecimal(0) if inactive? return BigDecimal(0) unless order_item_eligible?(order_item) discount_action.compute(order_item) end |
#inactive? ⇒ Boolean
22 23 24 |
# File 'app/models/spina/shop/discount.rb', line 22 def inactive? !active? end |
#order_item_eligible?(order_item) ⇒ Boolean
26 27 28 29 30 |
# File 'app/models/spina/shop/discount.rb', line 26 def order_item_eligible?(order_item) return false if inactive? return true unless discount_rule discount_rule.eligible?(order_item) end |