Class: Spree::Promotion::Rules::OneUsePerUser

Inherits:
Spree::PromotionRule show all
Defined in:
app/models/spree/promotion/rules/one_use_per_user.rb

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #eligibility_errors, for

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Spree::Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'app/models/spree/promotion/rules/one_use_per_user.rb', line 5

def applicable?(promotable)
  promotable.is_a?(Spree::Order)
end

#eligible?(order, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/spree/promotion/rules/one_use_per_user.rb', line 9

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))
    end
  else
    eligibility_errors.add(:base, eligibility_error_message(:no_user_specified))
  end

  eligibility_errors.empty?
end