forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit avoids doing 2 extra queries for every request (solidusio#1971) even when solidus store is not using solidus_multi_domain extension. This logic has now been moved to the solidus_multi_domain extension since it is needed only when multiple stores are expected (solidusio-contrib/solidus_multi_domain#67).
- Loading branch information
Showing
3 changed files
with
10 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
# 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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters