Class: SolidusFriendlyPromotions::Conditions::FirstRepeatPurchaseSince
- Inherits:
-
SolidusFriendlyPromotions::Condition
- Object
- Spree::Base
- SolidusFriendlyPromotions::Condition
- SolidusFriendlyPromotions::Conditions::FirstRepeatPurchaseSince
- Includes:
- OrderLevelCondition
- Defined in:
- app/models/solidus_friendly_promotions/conditions/first_repeat_purchase_since.rb
Instance Method Summary collapse
-
#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 included from OrderLevelCondition
Methods inherited from SolidusFriendlyPromotions::Condition
#applicable?, #eligibility_errors, #level, #preload_relations, #to_partial_path, #updateable?
Instance Method Details
#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
15 16 17 18 19 20 21 22 |
# File 'app/models/solidus_friendly_promotions/conditions/first_repeat_purchase_since.rb', line 15 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 |