Class: SolidusFriendlyPromotions::Conditions::OptionValue

Inherits:
SolidusFriendlyPromotions::Condition show all
Includes:
LineItemApplicableOrderCondition
Defined in:
app/models/solidus_friendly_promotions/conditions/option_value.rb

Instance Method Summary collapse

Methods included from LineItemApplicableOrderCondition

#applicable?, #eligible?, included, #level

Methods inherited from SolidusFriendlyPromotions::Condition

#applicable?, #eligibility_errors, #eligible?, #level, #preload_relations, #to_partial_path, #updateable?

Instance Method Details

#line_item_eligible?(line_item) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/solidus_friendly_promotions/conditions/option_value.rb', line 14

def line_item_eligible?(line_item)
  LineItemOptionValue.new(preferred_eligible_values: preferred_eligible_values).eligible?(line_item)
end

#order_eligible?(order) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/solidus_friendly_promotions/conditions/option_value.rb', line 10

def order_eligible?(order)
  order.line_items.any? { |item| line_item_eligible?(item) }
end

#preferred_eligible_valuesObject



18
19
20
21
22
23
24
25
# File 'app/models/solidus_friendly_promotions/conditions/option_value.rb', line 18

def preferred_eligible_values
  values = preferences[:eligible_values] || {}
  values.keys.map(&:to_i).zip(
    values.values.map do |value|
      (value.is_a?(Array) ? value : value.split(",")).map(&:to_i)
    end
  ).to_h
end