Sha256: 762bf0a43a44cfe9ee275cb389c835975f66904d6aab258d6f3286bc7dffc32c
Contents?: true
Size: 1.13 KB
Versions: 12
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true # Default implementation for finding the current store is given an HTTP request # # This is the new default behaviour, starting in Solidus 2.3.0. For the old # behaviour see Spree::StoreSelector::Legacy. # # This attempts to find a Spree::Store with a URL matching the domain name of # the request exactly. Failing that it will return the store marked as default. module Spree module StoreSelector class ByServerName def initialize(request) @request = request end # Chooses the current store based on a request. # @return [Spree::Store] def store server_name = @request.env['SERVER_NAME'] # We select a store which either matches our server name, or is default. # We sort by `default ASC` so that a store matching SERVER_NAME will come # first, and we will find that instead of the default. store = Spree::Store.where(url: server_name).or(Store.where(default: true)).order(default: :asc).first # Provide a fallback, mostly for legacy/testing purposes store || Spree::Store.new(url: server_name) end end end end
Version data entries
12 entries across 12 versions & 1 rubygems