Class: SolidusFriendlyPromotions::Conditions::LineItemProduct
Overview
A condition to apply a promotion only to line items with or without a chosen product
Constant Summary
collapse
- MATCH_POLICIES =
%w[include exclude].freeze
Instance Method Summary
collapse
#applicable?, #level
#applicable?, #eligibility_errors, #level, #to_partial_path, #updateable?
Instance Method Details
#eligible?(line_item, _options = {}) ⇒ Boolean
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_product.rb', line 25
def eligible?(line_item, _options = {})
order_includes_product = product_ids.include?(line_item.variant.product_id)
success = inverse? ? !order_includes_product : order_includes_product
unless success
message_code = inverse? ? :has_excluded_product : :no_applicable_products
eligibility_errors.add(
:base,
eligibility_error_message(message_code),
error_code: message_code
)
end
success
end
|
#preload_relations ⇒ Object
21
22
23
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_product.rb', line 21
def preload_relations
[:products]
end
|
#product_ids_string ⇒ Object
41
42
43
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_product.rb', line 41
def product_ids_string
product_ids.join(",")
end
|
#product_ids_string=(product_ids) ⇒ Object
45
46
47
|
# File 'app/models/solidus_friendly_promotions/conditions/line_item_product.rb', line 45
def product_ids_string=(product_ids)
self.product_ids = product_ids.to_s.split(",").map(&:strip)
end
|