Class: Spree::Promotion::Rules::ItemTotal
- Inherits:
-
Spree::PromotionRule
- Object
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::ItemTotal
- Defined in:
- app/models/spree/promotion/rules/item_total.rb
Overview
A rule 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`.
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 inherited from Spree::PromotionRule
#actionable?, #eligibility_errors, #preload_relations, #to_partial_path
Class Method Details
.operator_options ⇒ Object
24 25 26 27 28 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 24 def self. operators_map.map do |name, _method| [I18n.t(name, scope: 'spree.item_total_rule.operators'), name] end end |
.operators_map ⇒ Object
The list of allowed operators names mapped to their symbols.
17 18 19 20 21 22 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 17 def self.operators_map { gte: :>=, gt: :>, } end |
Instance Method Details
#applicable?(promotable) ⇒ Boolean
30 31 32 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 30 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _options = {}) ⇒ Boolean
34 35 36 37 38 39 40 41 42 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 34 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 |