Back to Spree

Multi-Store Spree Commerce

docs/developer/multi-store/quickstart.mdx

5.4.23.6 KB
Original Source

To enable multiple stores, you will need to add the spree_multi_store gem to your project via:

bash
bundle add spree_multi_store
<Info> Spree Multi-Store is licensed under the [AGPL v3 License](https://opensource.org/licenses/AGPL-3.0).

If you would like to use it in a commercial application, please contact us to obtain a commercial license. </Info>

<Frame type="glass" caption="Spree multi-store setup"> ![](/images/mulit_store_978x2.png) </Frame>

Store resources

Each Store can have its own resources. For example, a Store can have its own Products, Taxonomies, Promotions, etc.

ResourceRelationship
OrderOne Order belongs to one Store
ProductOne Product can be associated with many Store(s), you can pick and choose in which Store(s) each Product will be available
Payment MethodOne Payment Method can be associated with many Store(s), you can select in which Stores given Payment Method will be available on Checkout
TaxonomyOne Taxonomy belongs to one Store
PromotionOne Promotion can be associated with multiple Stores
Store CreditOne Store Credit belongs to and can be used in one Store

Current Store

Spree will try to determine the current store based on the current URL. If the URL does not match any of the stores in the database, Spree will fall back to the default store.

All Spree controllers or any other controllers that include Spree::Core::ControllerHelpers::Store have access to the current_store method which returns the Store matching the current URL.

All parts of Spree (API, Admin Panel) have this implemented.

<Info> Under the hood `current_store` calls [Spree::Stores::FindCurrent.new(url: url).execute](https://github.com/spree/spree/blob/main/core/app/finders/spree/stores/find_current.rb).

This logic can be easily overwritten by setting

ruby
Spree::Dependencies.current_store_finder = 'MyStoreFinderClass'

in config/initializers/spree.rb file </Info>

Default Store

If the system cannot find any Store that matches the current URL it will fall back to the Default Store.

You can set the default Store via Rails console:

ruby
Spree::Store.find(2).update(default: true)

To get the default store in your code or rails console type:

ruby
Spree::Store.default

Custom Domains

Spree supports managing custom domains for Stores. In the Admin Panel, you can manage custom domains for each Store in the Settings -> Domains page.

Setup multi-store application

Follow the setup guide to get started.