Class: Spree::Promotion::Rules::ItemTotal
Constant Summary
collapse
- OPERATORS_MIN =
['gt', 'gte']
- OPERATORS_MAX =
['lt', 'lte']
Instance Method Summary
collapse
#actionable?, #eligibility_errors, for, #human_description, #human_name, #key
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
30
31
32
33
34
|
# File 'app/models/spree/promotion/rules/item_total.rb', line 19
def eligible?(order, _options = {})
item_total = order.item_total
lower_limit_condition = item_total.send(preferred_operator_min == 'gte' ? :>= : :>, BigDecimal(preferred_amount_min.to_s))
if preferred_amount_max.present?
upper_limit_condition = item_total.send(preferred_operator_max == 'lte' ? :<= : :<, BigDecimal(preferred_amount_max.to_s))
else
upper_limit_condition = true
end
eligibility_errors.add(:base, ineligible_message_max(order)) unless upper_limit_condition
eligibility_errors.add(:base, ineligible_message_min(order)) unless lower_limit_condition
eligibility_errors.empty?
end
|