Class: SolidusFriendlyPromotions::Conditions::FirstRepeatPurchaseSince

Inherits:
SolidusFriendlyPromotions::Condition show all
Includes:
OrderLevelCondition
Defined in:
app/models/solidus_friendly_promotions/conditions/first_repeat_purchase_since.rb

Instance Method Summary collapse

Methods included from OrderLevelCondition

#applicable?, #level

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

Parameters:

  • order (Spree::Order)

Returns:

  • (Boolean)


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, _options = {})
  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