Class: Spree::PriceRules::UserRule

Inherits:
Spree::PriceRule show all
Defined in:
app/models/spree/price_rules/user_rule.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::PriceRule

registered_subclasses

Class Method Details

.descriptionObject



26
27
28
# File 'app/models/spree/price_rules/user_rule.rb', line 26

def self.description
  'Apply pricing to specific customers'
end

.human_nameObject

Public-facing label — keeps the wire ‘api_type` as `user_rule` (preference column is `user_ids`) so existing data stays valid, but every UI surface reads “Customer rule”.



33
34
35
# File 'app/models/spree/price_rules/user_rule.rb', line 33

def self.human_name
  'Customer rule'
end

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'app/models/spree/price_rules/user_rule.rb', line 18

def applicable?(context)
  return false unless context.user
  return true if preferred_user_ids.empty?

  # Compare as strings to support both integer and UUID primary keys
  preferred_user_ids.map(&:to_s).include?(context.user.id.to_s)
end

#usersObject



12
13
14
15
16
# File 'app/models/spree/price_rules/user_rule.rb', line 12

def users
  return [] if preferred_user_ids.blank?

  Spree.user_class.where(id: preferred_user_ids)
end