Class: SolidusPromotions::Conditions::OrderTaxon

Inherits:
SolidusPromotions::Condition show all
Includes:
TaxonCondition
Defined in:
app/models/solidus_promotions/conditions/order_taxon.rb

Constant Summary collapse

MATCH_POLICIES =
%w[any all none].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, #updateable?

Instance Method Details

#order_eligible?(order, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
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
# File 'app/models/solidus_promotions/conditions/order_taxon.rb', line 14

def order_eligible?(order, _options = {})
  line_item_taxon_ids = taxon_ids_in_order(order)

  case preferred_match_policy
  when "all"
    unless taxon_ids_with_children.all? { |taxon_and_descendant_ids| (line_item_taxon_ids & taxon_and_descendant_ids).any? }

      eligibility_errors.add(:base, eligibility_error_message(:missing_taxon), error_code: :missing_taxon)
    end
  when "any"
    if taxon_ids_with_children.none? { |taxon_and_descendant_ids| (line_item_taxon_ids & taxon_and_descendant_ids).any? }

      eligibility_errors.add(
        :base,
        eligibility_error_message(:no_matching_taxons),
        error_code: :no_matching_taxons
      )
    end
  when "none"
    if taxon_ids_with_children.any? { |taxon_and_descendant_ids| (line_item_taxon_ids & taxon_and_descendant_ids).any? }

      eligibility_errors.add(
        :base,
        eligibility_error_message(:has_excluded_taxon),
        error_code: :has_excluded_taxon
      )
    end
  end

  eligibility_errors.empty?
end

#to_partial_pathObject



46
47
48
# File 'app/models/solidus_promotions/conditions/order_taxon.rb', line 46

def to_partial_path
  "solidus_promotions/admin/condition_fields/taxon"
end