Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Align promotion rule eligibility error message with currency of the order. (#12762)

Josef Hovad28fca0d42b4b
diff --git a/core/app/models/spree/promotion/rules/item_total.rb b/core/app/models/spree/promotion/rules/item_total.rb
index 55d3b55496..7537454a53 100644
--- a/core/app/models/spree/promotion/rules/item_total.rb
+++ b/core/app/models/spree/promotion/rules/item_total.rb
@@ -27,39 +27,39 @@ module Spree
upper_limit_condition = true
end
- eligibility_errors.add(:base, ineligible_message_max) unless upper_limit_condition
- eligibility_errors.add(:base, ineligible_message_min) unless lower_limit_condition
+ 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
private
- def formatted_amount_min
- Spree::Money.new(preferred_amount_min).to_s
+ def formatted_amount_min(order)
+ Spree::Money.new(preferred_amount_min, currency: order.currency).to_s
end
- def formatted_amount_max
+ def formatted_amount_max(order)
if preferred_amount_max.present?
- Spree::Money.new(preferred_amount_max).to_s
+ Spree::Money.new(preferred_amount_max, currency: order.currency).to_s
else
Spree.t('no_maximum')
end
end
- def ineligible_message_max
+ def ineligible_message_max(order)
if preferred_operator_max == 'lt'
- eligibility_error_message(:item_total_more_than_or_equal, amount: formatted_amount_max)
+ eligibility_error_message(:item_total_more_than_or_equal, amount: formatted_amount_max(order))
else
- eligibility_error_message(:item_total_more_than, amount: formatted_amount_max)
+ eligibility_error_message(:item_total_more_than, amount: formatted_amount_max(order))
end
end
- def ineligible_message_min
+ def ineligible_message_min(order)
if preferred_operator_min == 'gte'
- eligibility_error_message(:item_total_less_than, amount: formatted_amount_min)
+ eligibility_error_message(:item_total_less_than, amount: formatted_amount_min(order))
else
- eligibility_error_message(:item_total_less_than_or_equal, amount: formatted_amount_min)
+ eligibility_error_message(:item_total_less_than_or_equal, amount: formatted_amount_min(order))
end
end
end
diff --git a/core/spec/models/spree/promotion/rules/item_total_spec.rb b/core/spec/models/spree/promotion/rules/item_total_spec.rb
index c23be84265..303b318a33 100644
--- a/core/spec/models/spree/promotion/rules/item_total_spec.rb
+++ b/core/spec/models/spree/promotion/rules/item_total_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Spree::Promotion::Rules::ItemTotal, type: :model do
let!(:store) { @default_store }
let(:rule) { Spree::Promotion::Rules::ItemTotal.new }
- let(:order) { double(:order) }
+ let(:order) { build(:order, store: store) }
before do
rule.preferred_amount_min = 50