Class: SolidusFriendlyPromotions::Conditions::LineItemTaxon
Constant Summary
collapse
- MATCH_POLICIES =
%w[include exclude].freeze
Instance Method Summary
collapse
#applicable?, #level
#applicable?, #eligibility_errors, #level, #to_partial_path
Instance Method Details
#eligible?(line_item, _options = {}) ⇒ Boolean
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb', line 22
def eligible?(line_item, _options = {})
found = Spree::Classification.where(
product_id: line_item.variant.product_id,
taxon_id: condition_taxon_ids_with_children
).exists?
case preferred_match_policy
when "include"
found
when "exclude"
!found
else
raise "unexpected match policy: #{preferred_match_policy.inspect}"
end
end
|
#preload_relations ⇒ Object
18
19
20
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb', line 18
def preload_relations
[:taxons]
end
|
#taxon_ids_string ⇒ Object
38
39
40
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb', line 38
def taxon_ids_string
taxons.pluck(:id).join(",")
end
|
#taxon_ids_string=(taxon_ids) ⇒ Object
42
43
44
45
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb', line 42
def taxon_ids_string=(taxon_ids)
taxon_ids = taxon_ids.to_s.split(",").map(&:strip)
self.taxons = Spree::Taxon.find(taxon_ids)
end
|
#updateable? ⇒ Boolean
47
48
49
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb', line 47
def updateable?
true
end
|