Class: Spree::Promotion::Rules::Product Private
- Inherits:
-
Spree::PromotionRule
- Object
- ActiveRecord::Base
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::Product
- Defined in:
- app/models/spree/promotion/rules/product.rb
Overview
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.
A rule to limit a promotion based on products in the order. Can require all or any of the products to be present. Valid products either come from assigned product group or are assingned directly to the rule.
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 all none)
Instance Method Summary collapse
- #actionable?(line_item) ⇒ Boolean private
- #applicable?(promotable) ⇒ Boolean private
- #eligible?(order, _options = {}) ⇒ Boolean private
-
#eligible_products ⇒ Object
private
scope/association that is used to test eligibility.
- #product_ids_string ⇒ Object private
- #product_ids_string=(s) ⇒ 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.
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/spree/promotion/rules/product.rb', line 51 def actionable?(line_item) case preferred_match_policy when 'any', 'all' product_ids.include? line_item.variant.product_id when 'none' product_ids.exclude? line_item.variant.product_id else raise "unexpected match policy: #{preferred_match_policy.inspect}" end 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.
24 25 26 |
# File 'app/models/spree/promotion/rules/product.rb', line 24 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/spree/promotion/rules/product.rb', line 28 def eligible?(order, = {}) return true if eligible_products.empty? case preferred_match_policy when 'all' unless eligible_products.all? { |p| order.products.include?(p) } eligibility_errors.add(:base, (:missing_product)) end when 'any' unless order.products.any? { |p| eligible_products.include?(p) } eligibility_errors.add(:base, (:no_applicable_products)) end when 'none' unless order.products.none? { |p| eligible_products.include?(p) } eligibility_errors.add(:base, (:has_excluded_product)) end else raise "unexpected match policy: #{preferred_match_policy.inspect}" end eligibility_errors.empty? end |
#eligible_products ⇒ 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.
scope/association that is used to test eligibility
20 21 22 |
# File 'app/models/spree/promotion/rules/product.rb', line 20 def eligible_products products end |
#product_ids_string ⇒ 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.
62 63 64 |
# File 'app/models/spree/promotion/rules/product.rb', line 62 def product_ids_string product_ids.join(',') end |
#product_ids_string=(s) ⇒ 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.
66 67 68 |
# File 'app/models/spree/promotion/rules/product.rb', line 66 def product_ids_string=(s) self.product_ids = s.to_s.split(',').map(&:strip) end |