Class: Spree::Promotion::Rules::Product
- Inherits:
-
Spree::PromotionRule
- Object
- ActiveRecord::Base
- Spree::PromotionRule
- Spree::Promotion::Rules::Product
- Defined in:
- app/models/spree/promotion/rules/product.rb
Constant Summary collapse
- MATCH_POLICIES =
%w(any all none)
Instance Method Summary collapse
- #applicable?(promotable) ⇒ Boolean
- #eligible?(order, options = {}) ⇒ Boolean
-
#eligible_products ⇒ Object
scope/association that is used to test eligibility.
- #product_ids_string ⇒ Object
- #product_ids_string=(s) ⇒ Object
Methods inherited from Spree::PromotionRule
Instance Method Details
#applicable?(promotable) ⇒ Boolean
18 19 20 |
# File 'app/models/spree/promotion/rules/product.rb', line 18 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, options = {}) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/promotion/rules/product.rb', line 22 def eligible?(order, = {}) return true if eligible_products.empty? if preferred_match_policy == 'all' eligible_products.all? {|p| order.products.include?(p) } elsif preferred_match_policy == 'any' order.products.any? {|p| eligible_products.include?(p) } else order.products.none? {|p| eligible_products.include?(p) } end end |
#eligible_products ⇒ Object
scope/association that is used to test eligibility
14 15 16 |
# File 'app/models/spree/promotion/rules/product.rb', line 14 def eligible_products products end |
#product_ids_string ⇒ Object
33 34 35 |
# File 'app/models/spree/promotion/rules/product.rb', line 33 def product_ids_string product_ids.join(',') end |
#product_ids_string=(s) ⇒ Object
37 38 39 |
# File 'app/models/spree/promotion/rules/product.rb', line 37 def product_ids_string=(s) self.product_ids = s.to_s.split(',').map(&:strip) end |