Class: Spree::Promotion::Rules::FirstRepeatPurchaseSince
- Inherits:
-
Spree::PromotionRule
- Object
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::FirstRepeatPurchaseSince
- Defined in:
- app/models/spree/promotion/rules/first_repeat_purchase_since.rb
Instance Method Summary collapse
-
#applicable?(promotable) ⇒ Boolean
This promotion is applicable to orders only.
-
#eligible?(order, _options = {}) ⇒ Boolean
This is never eligible if the order does not have a user, and that user does not have any previous completed orders.
Methods inherited from Spree::PromotionRule
#actionable?, #eligibility_errors, #preload_relations, #to_partial_path
Instance Method Details
#applicable?(promotable) ⇒ Boolean
This promotion is applicable to orders only.
11 12 13 |
# File 'app/models/spree/promotion/rules/first_repeat_purchase_since.rb', line 11 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _options = {}) ⇒ Boolean
This is never eligible if the order does not have a user, and that user does not have any previous completed orders.
This is eligible if the user’s most recently completed order is more than the preferred days ago
19 20 21 22 23 24 25 26 |
# File 'app/models/spree/promotion/rules/first_repeat_purchase_since.rb', line 19 def eligible?(order, = {}) return false unless order.user last_order = last_completed_order(order.user) return false unless last_order last_order.completed_at < preferred_days_ago.days.ago end |