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.

Fixed Country Promotion rule for Store default country

Damian Legawiec1f81e2eea039
diff --git a/core/app/models/spree/promotion/rules/country.rb b/core/app/models/spree/promotion/rules/country.rb
index 3126c6793e..247725926d 100644
--- a/core/app/models/spree/promotion/rules/country.rb
+++ b/core/app/models/spree/promotion/rules/country.rb
@@ -11,7 +11,7 @@ module Spree
def eligible?(order, options = {})
country_id = options[:country_id] || order.ship_address.try(:country_id)
- unless country_id.eql?(preferred_country_id || Spree::Country.default)
+ unless country_id.eql?(preferred_country_id || order.store.default_country_id)
eligibility_errors.add(:base, eligibility_error_message(:wrong_country))
end
diff --git a/core/spec/models/spree/promotion/rules/country_spec.rb b/core/spec/models/spree/promotion/rules/country_spec.rb
index 45fee571ef..6052f1233d 100644
--- a/core/spec/models/spree/promotion/rules/country_spec.rb
+++ b/core/spec/models/spree/promotion/rules/country_spec.rb
@@ -1,13 +1,12 @@
require 'spec_helper'
describe Spree::Promotion::Rules::Country, type: :model do
- let(:rule) { Spree::Promotion::Rules::Country.new }
- let(:order) { create(:order) }
+ let!(:store) { create(:store, default_country: other_country) }
+ let(:rule) { described_class.new }
+ let(:order) { create(:order, store: store) }
let(:country) { create(:country) }
let(:other_country) { create(:country) }
- before { allow(Spree::Country).to receive(:default) { other_country } }
-
context 'preferred country is set' do
before { rule.preferred_country_id = country.id }