Class: SolidusPromotions::Conditions::Taxon

Inherits:
SolidusPromotions::Condition show all
Includes:
LineItemApplicableOrderLevelCondition, TaxonCondition
Defined in:
app/models/solidus_promotions/conditions/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 included from LineItemApplicableOrderLevelCondition

#applicable?, included, #level

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

#line_item_eligible?(line_item, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/solidus_promotions/conditions/taxon.rb', line 27

def line_item_eligible?(line_item, _options = {})
  line_item_match_policy = preferred_match_policy.in?(%w[any all]) ? "include" : "exclude"
  line_item_condition = LineItemTaxon.new(taxons:, preferred_match_policy: line_item_match_policy)

  # Hydrate the instance cache with our @taxon_ids_with_children cache\
  line_item_condition.taxons_ids_with_children = taxon_ids_with_children

  result = line_item_condition.line_item_eligible?(line_item)
  @eligibility_errors = line_item_condition.eligibility_errors
  result
end

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

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'app/models/solidus_promotions/conditions/taxon.rb', line 16

def order_eligible?(order, _options = {})
  order_condition = OrderTaxon.new(taxons:, preferred_match_policy:)

  # Hydrate the instance cache with our @taxon_ids_with_children cache
  order_condition.taxons_ids_with_children = taxon_ids_with_children

  order_condition.order_eligible?(order)
  @eligibility_errors = order_condition.eligibility_errors
  eligibility_errors.empty?
end

#price_eligible?(price, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/solidus_promotions/conditions/taxon.rb', line 39

def price_eligible?(price, _options = {})
  price_match_policy = preferred_match_policy.in?(%w[any all]) ? "include" : "exclude"
  price_condition = PriceTaxon.new(taxons:, preferred_match_policy: price_match_policy)

  # Hydrate the instance cache with our @taxon_ids_with_children cache
  price_condition.taxons_ids_with_children = taxon_ids_with_children

  result = price_condition.price_eligible?(price)
  @eligibility_errors = price_condition.eligibility_errors
  result
end