diff --git a/core/app/models/spree/current_store_selector.rb b/core/app/models/spree/current_store_selector.rb index 40e527dc3b5..d31ea74c324 100644 --- a/core/app/models/spree/current_store_selector.rb +++ b/core/app/models/spree/current_store_selector.rb @@ -1,5 +1,8 @@ # Default class for deciding what the current store is, given an HTTP request -# This is an extension point used in Spree::Core::ControllerHelpers::Store +# +# To use a custom version of this class just set the preference: +# Spree::Config.current_store_selector_class = CustomCurrentStoreSelector +# # Custom versions of this class must respond to a store instance method module Spree class CurrentStoreSelector @@ -7,22 +10,12 @@ def initialize(request) @request = request end - # Chooses the current store based on a request. - # Checks request headers for HTTP_SPREE_STORE and falls back to - # looking up by the requesting server's name. + # Select the store to be used. In this basic implementation the + # default store will be always selected. + # # @return [Spree::Store] def store - if store_key - Spree::Store.current(store_key) - else - Spree::Store.default - end - end - - private - - def store_key - @request.headers['HTTP_SPREE_STORE'] || @request.env['SERVER_NAME'] + Spree::Store.default end end end diff --git a/core/spec/lib/spree/core/current_store_spec.rb b/core/spec/lib/spree/core/current_store_spec.rb index 3644d01a9f6..48e607a6ef4 100644 --- a/core/spec/lib/spree/core/current_store_spec.rb +++ b/core/spec/lib/spree/core/current_store_spec.rb @@ -5,32 +5,12 @@ subject { Spree::Deprecation.silence { Spree::Core::CurrentStore.new(request).store } } context "with a default" do - let(:request) { double(headers: {}, env: {}) } + let(:request) { double('any request') } let!(:store_1) { create :store, default: true } it "returns the default store" do expect(subject).to eq(store_1) end - - context "with a domain match" do - let(:request) { double(headers: {}, env: { "SERVER_NAME" => url } ) } - let(:url) { "server-name.org" } - let!(:store_2) { create :store, default: false, url: url } - - it "returns the store with the matching domain" do - expect(subject).to eq(store_2) - end - - context "with headers" do - let(:request) { double(headers: { "HTTP_SPREE_STORE" => headers_code }, env: {}) } - let(:headers_code) { "HEADERS" } - let!(:store_3) { create :store, code: headers_code, default: false } - - it "returns the store with the matching code" do - expect(subject).to eq(store_3) - end - end - end end it 'is deprecated' do diff --git a/core/spec/models/spree/current_store_selector_spec.rb b/core/spec/models/spree/current_store_selector_spec.rb index dbac5a538c8..0e95bd42936 100644 --- a/core/spec/models/spree/current_store_selector_spec.rb +++ b/core/spec/models/spree/current_store_selector_spec.rb @@ -5,32 +5,12 @@ subject { Spree::CurrentStoreSelector.new(request).store } context "with a default" do - let(:request) { double(headers: {}, env: {}) } + let(:request) { double('any request') } let!(:store_1) { create :store, default: true } it "returns the default store" do expect(subject).to eq(store_1) end - - context "with a domain match" do - let(:request) { double(headers: {}, env: { "SERVER_NAME" => url } ) } - let(:url) { "server-name.org" } - let!(:store_2) { create :store, default: false, url: url } - - it "returns the store with the matching domain" do - expect(subject).to eq(store_2) - end - - context "with headers" do - let(:request) { double(headers: { "HTTP_SPREE_STORE" => headers_code }, env: {}) } - let(:headers_code) { "HEADERS" } - let!(:store_3) { create :store, code: headers_code, default: false } - - it "returns the store with the matching code" do - expect(subject).to eq(store_3) - end - end - end end end end