Class: SolidusFriendlyPromotions::Conditions::ItemTotal
- Inherits:
-
SolidusFriendlyPromotions::Condition
- Object
- Spree::Base
- SolidusFriendlyPromotions::Condition
- SolidusFriendlyPromotions::Conditions::ItemTotal
- 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
Class Method Summary collapse
- .operator_options ⇒ Object
-
.operators_map ⇒ Object
The list of allowed operators names mapped to their symbols.
Instance Method Summary collapse
Methods included from OrderLevelCondition
Methods inherited from SolidusFriendlyPromotions::Condition
#applicable?, #eligibility_errors, #level, #preload_relations, #to_partial_path, #updateable?
Class Method Details
.operator_options ⇒ Object
25 26 27 28 29 |
# File 'app/models/solidus_friendly_promotions/conditions/item_total.rb', line 25 def self. operators_map.map do |name, _method| [I18n.t(name, scope: "solidus_friendly_promotions.item_total_condition.operators"), name] end end |
.operators_map ⇒ Object
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
31 32 33 34 35 36 37 38 39 |
# File 'app/models/solidus_friendly_promotions/conditions/item_total.rb', line 31 def eligible?(order, = {}) return false unless order.currency == preferred_currency unless total_for_order(order).send(operator, threshold) eligibility_errors.add(:base, , error_code: ineligible_error_code) end eligibility_errors.empty? end |