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?, additional_permitted_attributes, #eligibility_errors, for, human_description, #human_description, human_name, #human_name, #key

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:



10
11
12
# File 'app/models/spree/promotion/rules/customer_group.rb', line 10

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

#customer_groupsObject



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

def customer_groups
  return Spree::CustomerGroup.none if preferred_customer_group_ids.blank?

  Spree::CustomerGroup.where(id: preferred_customer_group_ids)
end

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

Returns:



20
21
22
23
24
25
26
27
# File 'app/models/spree/promotion/rules/customer_group.rb', line 20

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