Class: SolidusPromotions::Conditions::PriceTaxon
- Inherits:
-
SolidusPromotions::Condition
- Object
- Spree::Base
- SolidusPromotions::Condition
- SolidusPromotions::Conditions::PriceTaxon
- Includes:
- TaxonCondition
- Defined in:
- app/models/solidus_promotions/conditions/price_taxon.rb
Constant Summary collapse
- MATCH_POLICIES =
%w[include exclude].freeze
Instance Method Summary collapse
Methods included from TaxonCondition
included, #preload_relations, #taxon_ids_string, #taxon_ids_string=, #taxons_ids_with_children=
Methods inherited from SolidusPromotions::Condition
#applicable?, applicable_to, #eligibility_errors, #eligible?, eligible_method_for, inherited, #level, #preload_relations, #to_partial_path, #updateable?
Instance Method Details
#price_eligible?(price, _options = {}) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/solidus_promotions/conditions/price_taxon.rb', line 14 def price_eligible?(price, = {}) price_taxon_ids = price.variant.product.classifications.map(&:taxon_id) case preferred_match_policy when "include" taxon_ids_with_children.any? { |taxon_and_descendant_ids| (price_taxon_ids & taxon_and_descendant_ids).any? } when "exclude" taxon_ids_with_children.none? { |taxon_and_descendant_ids| (price_taxon_ids & taxon_and_descendant_ids).any? } else raise "unexpected match policy: #{preferred_match_policy.inspect}" end end |