Class: Spree::Promotion::Rules::OptionValue Private
- Inherits:
-
Spree::PromotionRule
- Object
- ActiveRecord::Base
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::OptionValue
- 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 collapse
- 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
- #actionable?(line_item) ⇒ Boolean private
- #applicable?(promotable) ⇒ Boolean private
- #eligible?(promotable, _options = {}) ⇒ Boolean private
- #preferred_eligible_values ⇒ Object private
Methods inherited from Spree::PromotionRule
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
#actionable?(line_item) ⇒ Boolean
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.
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 |
#applicable?(promotable) ⇒ Boolean
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.
9 10 11 |
# File 'app/models/spree/promotion/rules/option_value.rb', line 9 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(promotable, _options = {}) ⇒ Boolean
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.
13 14 15 16 17 18 |
# File 'app/models/spree/promotion/rules/option_value.rb', line 13 def eligible?(promotable, = {}) case preferred_match_policy when 'any' promotable.line_items.any? { |item| actionable?(item) } end end |
#preferred_eligible_values ⇒ Object
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 |