Class: Spree::Promotion::Rules::ItemTotal
- Inherits:
-
Spree::PromotionRule
- Object
- ApplicationRecord
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::ItemTotal
- Defined in:
- app/models/spree/promotion/rules/item_total.rb
Constant Summary collapse
- OPERATORS_MIN =
['gt', 'gte']
- OPERATORS_MAX =
['lt', 'lte']
Instance Method Summary collapse
Methods inherited from Spree::PromotionRule
#actionable?, #eligibility_errors, for
Methods inherited from Base
belongs_to_required_by_default, page, spree_base_scopes
Methods included from Spree::Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#applicable?(promotable) ⇒ Boolean
15 16 17 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 15 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, _options = {}) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/spree/promotion/rules/item_total.rb', line 19 def eligible?(order, = {}) item_total = order.item_total lower_limit_condition = item_total.send(preferred_operator_min == 'gte' ? :>= : :>, BigDecimal.new(preferred_amount_min.to_s)) upper_limit_condition = item_total.send(preferred_operator_max == 'lte' ? :<= : :<, BigDecimal.new(preferred_amount_max.to_s)) eligibility_errors.add(:base, ) unless upper_limit_condition eligibility_errors.add(:base, ) unless lower_limit_condition eligibility_errors.empty? end |