Class: Spree::Promotion::Rules::ItemTotal
- Inherits:
-
Spree::PromotionRule
- Object
- ActiveRecord::Base
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::ItemTotal
- Includes:
- ActiveSupport::Deprecation::DeprecatedConstantAccessor
- 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`.
Constant Summary collapse
- OPERATORS =
Deprecated.
operators_map.keys.map(&:to_s)
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, for, #preload_relations, #to_partial_path
Methods inherited from Base
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Class Method Details
.operator_options ⇒ Object
26 27 28 29 30 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 26 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.
19 20 21 22 23 24 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 19 def self.operators_map { gte: :>=, gt: :>, } end |
Instance Method Details
#applicable?(promotable) ⇒ Boolean
41 42 43 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 41 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _options = {}) ⇒ Boolean
45 46 47 48 49 50 51 52 53 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 45 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 |