Class: Spree::PriceRules::CustomerGroupRule

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::PriceRule

human_name

Class Method Details

.descriptionObject



16
17
18
# File 'app/models/spree/price_rules/customer_group_rule.rb', line 16

def self.description
  Spree.t('price_rules.customer_group_rule.description')
end

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
# File 'app/models/spree/price_rules/customer_group_rule.rb', line 6

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

  user_customer_group_ids = Spree::CustomerGroupUser.where(user_id: context.user.id).pluck(:customer_group_id).map(&:to_s)

  # Compare as strings to support both integer and UUID primary keys
  (preferred_customer_group_ids.map(&:to_s) & user_customer_group_ids).any?
end