Class: Spree::Promotion::Rules::CustomerGroup

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

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #eligibility_errors, for, #human_description, #human_name, #key

Instance Method Details

#applicable?(promotable) ⇒ Boolean



7
8
9
# File 'app/models/spree/promotion/rules/customer_group.rb', line 7

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

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



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

def eligible?(order, _options = {})
  return false unless order.user_id.present?
  return false if preferred_customer_group_ids.empty?

  user_customer_group_ids = Spree::CustomerGroupUser.where(user_id: order.user_id).pluck(:customer_group_id).map(&:to_s)

  (preferred_customer_group_ids.map(&:to_s) & user_customer_group_ids).any?
end