Class: SolidusFriendlyPromotions::Conditions::ItemTotal

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

Overview

A condition to apply to an order greater than (or greater than or equal to) a specific amount

To add extra operators please override ‘self.operators_map` or any other helper method. To customize the error message you can also override `ineligible_message`.

Direct Known Subclasses

DiscountedItemTotal

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OrderLevelCondition

#applicable?, #level

Methods inherited from SolidusFriendlyPromotions::Condition

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

Class Method Details

.operator_optionsObject



25
26
27
28
29
# File 'app/models/solidus_friendly_promotions/conditions/item_total.rb', line 25

def self.operator_options
  operators_map.map do |name, _method|
    [I18n.t(name, scope: "solidus_friendly_promotions.item_total_condition.operators"), name]
  end
end

.operators_mapObject

The list of allowed operators names mapped to their symbols.



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

def self.operators_map
  {
    gte: :>=,
    gt: :>
  }
end

Instance Method Details

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

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'app/models/solidus_friendly_promotions/conditions/item_total.rb', line 31

def eligible?(order, _options = {})
  return false unless order.currency == preferred_currency

  unless total_for_order(order).send(operator, threshold)
    eligibility_errors.add(:base, ineligible_message, error_code: ineligible_error_code)
  end

  eligibility_errors.empty?
end