Class: SolidusFriendlyPromotions::Conditions::OneUsePerUser

Inherits:
SolidusFriendlyPromotions::Condition show all
Includes:
OrderLevelCondition
Defined in:
app/models/solidus_friendly_promotions/conditions/one_use_per_user.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

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/solidus_friendly_promotions/conditions/one_use_per_user.rb', line 8

def eligible?(order, _options = {})
  if order.user.present?
    if promotion.used_by?(order.user, [order])
      eligibility_errors.add(
        :base,
        eligibility_error_message(:limit_once_per_user),
        error_code: :limit_once_per_user
      )
    end
  else
    eligibility_errors.add(:base, eligibility_error_message(:no_user_specified), error_code: :no_user_specified)
  end

  eligibility_errors.empty?
end