Skip to content

Commit

Permalink
Add instructions on how to use additional ItemTotal operators
Browse files Browse the repository at this point in the history
Also support a generic message that can work with any operator.
  • Loading branch information
elia committed May 4, 2021
1 parent 0a5110f commit 3f1be03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/app/models/spree/promotion/rules/item_total.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class Promotion < Spree::Base
module Rules
# 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 ItemTotal < PromotionRule
include ActiveSupport::Deprecation::DeprecatedConstantAccessor

Expand Down Expand Up @@ -71,10 +74,13 @@ def formatted_amount
end

def ineligible_message
if preferred_operator.to_s == 'gte'
case preferred_operator.to_s
when 'gte'
eligibility_error_message(:item_total_less_than, amount: formatted_amount)
else
when 'gt'
eligibility_error_message(:item_total_less_than_or_equal, amount: formatted_amount)
else
eligibility_error_message(:item_total_doesnt_match_with_operator, amount: formatted_amount, operator: preferred_operator)
end
end

Expand Down
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,8 @@ en:
%{amount}.
item_total_less_than_or_equal: This coupon code can't be applied to orders
less than or equal to %{amount}.
item_total_doesnt_match_with_operator: This coupon code can't be applied to
orders %{operator} %{amount}.
limit_once_per_user: This coupon code can only be used once per user.
missing_product: This coupon code can't be applied because you don't have
all of the necessary products in your cart.
Expand Down

0 comments on commit 3f1be03

Please sign in to comment.