Class: SolidusPromotions::Conditions::Product

Inherits:
SolidusPromotions::Condition show all
Includes:
LineItemApplicableOrderLevelCondition, ProductCondition
Defined in:
app/models/solidus_promotions/conditions/product.rb

Overview

A condition to limit a promotion based on products in the order. Can require all or any of the products to be present. Valid products either come from assigned product group or are assingned directly to the condition.

Constant Summary collapse

MATCH_POLICIES =
%w[any all none only].freeze

Instance Method Summary collapse

Methods included from ProductCondition

included, #preload_relations, #product_ids_string, #product_ids_string=

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
# File 'app/models/solidus_promotions/conditions/product.rb', line 27

def line_item_eligible?(line_item, _options = {})
  line_item_match_policy = preferred_match_policy.in?(%w[any all only]) ? "include" : "exclude"
  line_item_condition = LineItemProduct.new(products:, preferred_match_policy: line_item_match_policy)
  line_item_condition.line_item_eligible?(line_item)
  @eligibility_errors = line_item_condition.eligibility_errors
  eligibility_errors.empty?
end

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

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'app/models/solidus_promotions/conditions/product.rb', line 20

def order_eligible?(order, _options = {})
  order_condition = OrderProduct.new(products:, preferred_match_policy:)
  order_condition.order_eligible?(order)
  @eligibility_errors = order_condition.eligibility_errors
  eligibility_errors.empty?
end

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

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'app/models/solidus_promotions/conditions/product.rb', line 35

def price_eligible?(price, _options = {})
  price_match_policy = preferred_match_policy.in?(%w[any all only]) ? "include" : "exclude"
  price_condition = PriceProduct.new(products:, preferred_match_policy: price_match_policy)
  price_condition.price_eligible?(price)
  @eligibility_errors = price_condition.eligibility_errors
  eligibility_errors.empty?
end