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: don't raise 404 when no store on root domain (#12897)

Damian Legawiec5001cc14212d
diff --git a/core/lib/spree/core/controller_helpers/store.rb b/core/lib/spree/core/controller_helpers/store.rb
index de35685f49..d62fb4e6cb 100644
--- a/core/lib/spree/core/controller_helpers/store.rb
+++ b/core/lib/spree/core/controller_helpers/store.rb
@@ -68,8 +68,14 @@ module Spree
end
def raise_record_not_found_if_store_is_not_found
+ return if skip_store_lookup?
+
raise ActiveRecord::RecordNotFound if current_store.nil?
end
+
+ def skip_store_lookup?
+ Spree.root_domain.present? && Spree.root_domain.include?(request.env['SERVER_NAME'])
+ end
end
end
end
diff --git a/core/spec/lib/spree/core/controller_helpers/store_spec.rb b/core/spec/lib/spree/core/controller_helpers/store_spec.rb
index d7a8b08ed2..224eef1c94 100644
--- a/core/spec/lib/spree/core/controller_helpers/store_spec.rb
+++ b/core/spec/lib/spree/core/controller_helpers/store_spec.rb
@@ -191,6 +191,8 @@ describe Spree::Core::ControllerHelpers::Store, type: :controller do
end
describe '#raise_record_not_found_if_store_is_not_found' do
+ let(:store) { create :store }
+
context 'when the store is not found' do
before do
allow(controller).to receive(:current_store).and_return(nil)
@@ -200,5 +202,26 @@ describe Spree::Core::ControllerHelpers::Store, type: :controller do
expect { controller.send(:raise_record_not_found_if_store_is_not_found) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
+
+ context 'with root_domain set' do
+ before do
+ allow(Spree).to receive(:root_domain).and_return('example.com')
+ controller.request.env['SERVER_NAME'] = 'example.com'
+ end
+
+ it 'does not raise an exception' do
+ expect { controller.send(:raise_record_not_found_if_store_is_not_found) }.not_to raise_error
+ end
+ end
+
+ context 'when store is found' do
+ before do
+ allow(controller).to receive(:current_store).and_return(store)
+ end
+
+ it 'does not raise an exception' do
+ expect { controller.send(:raise_record_not_found_if_store_is_not_found) }.not_to raise_error
+ end
+ end
end
end