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

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

MATCH_POLICIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w(any)

Instance Method Summary (collapse)

Methods inherited from Spree::PromotionRule

#eligibility_errors, for

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

- (Boolean) actionable?(line_item)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

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).present?
end

- (Boolean) applicable?(promotable)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


9
10
11
# File 'app/models/spree/promotion/rules/option_value.rb', line 9

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

- (Boolean) eligible?(promotable, _options = {})

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

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

- (Object) preferred_eligible_values

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def preferred_eligible_values
  values = preferences[:eligible_values] || {}
  Hash[values.keys.map(&:to_i).zip(
    values.values.map do |v|
      (v.is_a?(Array) ? v : v.split(",")).map(&:to_i)
    end
  )]
end