Class: SolidusPromotions::Conditions::OrderProduct
- Inherits:
-
SolidusPromotions::Condition
- Object
- Spree::Base
- SolidusPromotions::Condition
- SolidusPromotions::Conditions::OrderProduct
- Includes:
- ProductCondition
- Defined in:
- app/models/solidus_promotions/conditions/order_product.rb
Overview
A condition 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 condition.
Constant Summary collapse
- MATCH_POLICIES =
%w[any all none only].freeze
Instance Method Summary collapse
-
#eligible_products ⇒ Object
scope/association that is used to test eligibility.
- #order_eligible?(order) ⇒ Boolean
- #to_partial_path ⇒ Object
Methods included from ProductCondition
included, #preload_relations, #product_ids_string, #product_ids_string=
Methods inherited from SolidusPromotions::Condition
#applicable?, applicable_to, #eligibility_errors, #eligible?, eligible_method_for, inherited, #level, #preload_relations, #updateable?
Instance Method Details
#eligible_products ⇒ Object
scope/association that is used to test eligibility
19 20 21 |
# File 'app/models/solidus_promotions/conditions/order_product.rb', line 19 def eligible_products products end |
#order_eligible?(order) ⇒ Boolean
23 24 25 26 27 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/solidus_promotions/conditions/order_product.rb', line 23 def order_eligible?(order) return true if eligible_products.empty? case preferred_match_policy when "all" unless eligible_products.all? { |product| order_products(order).include?(product) } eligibility_errors.add(:base, (:missing_product), error_code: :missing_product) end when "any" unless order_products(order).any? { |product| eligible_products.include?(product) } eligibility_errors.add(:base, (:no_applicable_products), error_code: :no_applicable_products) end when "none" unless order_products(order).none? { |product| eligible_products.include?(product) } eligibility_errors.add(:base, (:has_excluded_product), error_code: :has_excluded_product) end when "only" unless order_products(order).all? { |product| eligible_products.include?(product) } eligibility_errors.add(:base, (:has_excluded_product), error_code: :has_excluded_product) end end eligibility_errors.empty? end |
#to_partial_path ⇒ Object
51 52 53 |
# File 'app/models/solidus_promotions/conditions/order_product.rb', line 51 def to_partial_path "solidus_promotions/admin/condition_fields/product" end |