Class: Spree::Promotion::Rules::Taxon
- Inherits:
-
Spree::PromotionRule
- Object
- ActiveRecord::Base
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::Taxon
- Defined in:
- app/models/spree/promotion/rules/taxon.rb
Constant Summary collapse
- MATCH_POLICIES =
%w(any all none)
Instance Method Summary collapse
-
#actionable?(line_item) ⇒ Boolean
TODO: Fix bug - well described by jhawthorn in #1409: ‘eligible?` checks the configured taxons and all descendants, `actionable?` only seems to check against the taxons themselves (not children).
- #applicable?(promotable) ⇒ Boolean
- #eligible?(order, _options = {}) ⇒ Boolean
- #taxon_ids_string ⇒ Object
- #taxon_ids_string=(taxon_ids) ⇒ Object
Methods inherited from Spree::PromotionRule
#eligibility_errors, for, #to_partial_path
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
Methods included from Spree::Preferences::Preferable
#admin_form_preference_names, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#actionable?(line_item) ⇒ Boolean
TODO: Fix bug - well described by jhawthorn in #1409: ‘eligible?` checks the configured taxons and all descendants, `actionable?` only seems to check against the taxons themselves (not children)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/spree/promotion/rules/taxon.rb', line 54 def actionable?(line_item) found = Spree::Classification.where( product_id: line_item.variant.product_id, taxon_id: taxon_ids ).exists? case preferred_match_policy when 'any', 'all' found when 'none' !found else # Change this to an exception in a future version of Solidus warn_invalid_match_policy(assume: 'any') found end end |
#applicable?(promotable) ⇒ Boolean
16 17 18 |
# File 'app/models/spree/promotion/rules/taxon.rb', line 16 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _options = {}) ⇒ Boolean
20 21 22 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/spree/promotion/rules/taxon.rb', line 20 def eligible?(order, = {}) order_taxons = taxons_in_order(order) case preferred_match_policy when 'all' matches_all = taxons.all? do |rule_taxon| order_taxons.where(id: rule_taxon.self_and_descendants.ids).exists? end unless matches_all eligibility_errors.add(:base, (:missing_taxon)) end when 'any' unless order_taxons.where(id: rule_taxon_ids_with_children).exists? eligibility_errors.add(:base, (:no_matching_taxons)) end when 'none' if order_taxons.where(id: rule_taxon_ids_with_children).exists? eligibility_errors.add(:base, (:has_excluded_taxon)) end else # Change this to an exception in a future version of Solidus warn_invalid_match_policy(assume: 'any') unless order_taxons.where(id: rule_taxon_ids_with_children).exists? eligibility_errors.add(:base, (:no_matching_taxons)) end end eligibility_errors.empty? end |
#taxon_ids_string ⇒ Object
72 73 74 |
# File 'app/models/spree/promotion/rules/taxon.rb', line 72 def taxon_ids_string taxons.pluck(:id).join(',') end |