Class: Spree::Promotion::Rules::OptionValue

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

Constant Summary collapse

MATCH_POLICIES =
%w(any)

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#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

#actionable?(line_item) ⇒ Boolean


33
34
35
36
37
38
# File 'app/models/spree/promotion/rules/option_value.rb', line 33

def actionable?(line_item)
  pid = line_item.product.id
  ovids = line_item.variant.option_values.pluck(:id)

  product_ids.include?(pid) && (value_ids(pid) - ovids).empty?
end

#applicable?(promotable) ⇒ Boolean


22
23
24
# File 'app/models/spree/promotion/rules/option_value.rb', line 22

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

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


26
27
28
29
30
31
# File 'app/models/spree/promotion/rules/option_value.rb', line 26

def eligible?(promotable, _options = {})
  case preferred_match_policy
  when 'any'
    promotable.line_items.any? { |item| actionable?(item) }
  end
end