Class: Promotion::Rules::Product
- Inherits:
-
PromotionRule
- Object
- PromotionRule
- Promotion::Rules::Product
- Defined in:
- app/models/promotion/rules/product.rb
Overview
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 =
%w(any all)
Instance Method Summary collapse
- #eligible?(order) ⇒ Boolean
-
#eligible_products ⇒ Object
scope/association that is used to test eligibility.
- #product_ids_string ⇒ Object
- #product_ids_string=(s) ⇒ Object
- #products_source=(source) ⇒ Object
Instance Method Details
#eligible?(order) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'app/models/promotion/rules/product.rb', line 17 def eligible?(order) return true if eligible_products.empty? if preferred_match_policy == 'all' eligible_products.all? {|p| order.products.include?(p) } else order.products.any? {|p| eligible_products.include?(p) } end end |
#eligible_products ⇒ Object
scope/association that is used to test eligibility
13 14 15 |
# File 'app/models/promotion/rules/product.rb', line 13 def eligible_products product_group ? product_group.products : products end |
#product_ids_string ⇒ Object
33 34 35 |
# File 'app/models/promotion/rules/product.rb', line 33 def product_ids_string product_ids.join(',') end |
#product_ids_string=(s) ⇒ Object
36 37 38 |
# File 'app/models/promotion/rules/product.rb', line 36 def product_ids_string=(s) self.product_ids = s.to_s.split(',').map(&:strip) end |
#products_source=(source) ⇒ Object
27 28 29 30 31 |
# File 'app/models/promotion/rules/product.rb', line 27 def products_source=(source) if source.to_s == 'manual' self.product_group_id = nil end end |