What's new in nopCommerce 3.0 - part 2 - multi store support.
We are back with more insight into the currently buzzing and much awaited nopCommerce 3.0 release. Today we are going to look at the multi-store support in nopCommerce.
As usual we have something for all nopCommerce users - store owners, developers and Nop-Templates customers. But let's start with the store owners. So what does it really mean to have more than one store running in nopCommerce?
It means that you can have more than one website\store (different domains or subdomains) running in the same nopCommerce installation. In other words if I was a retailer who was selling two major brands Brand1 and Brand2 and my business required that these brands are sold on separate websites\stores I would not have to create two separate nopCommerce installations to do this.
How does this help?
- For starters you have only one database and web application to cater for.
- You have a single administration for all your websites, where you can manage your catalog, customer and order data.
- Your customers have a single login for all your stores.
- You can share catalog data between stores, have a product in more than one store for example.
- Since your customer data is shared you can use it between stores for marketing campaigns and different crosell\upsell implementations.
Most of the entities in your nopCommerce installation like categories, products, etc. can be limited per store. But it is important to note that your customers cannot be.
Why is this important? Because you cannot dedicate an administrator for only one store. Your catalog, customer and order data is visible to all administrators.
This means that the multi-store support in nopCommerce is really for single store owners with more than one online store. You would not have a shopify or bigcommerce style of system. You cannot have such a system anyway, as it requires a multi-tenant application and nopCommerce is not multi-tenant.
So we have established that nopCommerce 3.0 is a good fit for store owners who would like to have more than one store. To be able to plan their multi store implementation, these store owners should know what entities\data can be limited per store. In the initial release of nopCommerce 3.0 these are the entities that will support multi-store (can be limited per store):
- Message Templates
Different themes can also be configured for different stores.
And these are the entities that do not support multi-store but will probably do in the future:
- Shipping Methods - you can vote for it here: http://nopcommerce.codeplex.com/workitem/11404
- Payment Methods - you can cote for it here: http://nopcommerce.codeplex.com/workitem/11406
- Plugins - you can vote for it here: http://nopcommerce.codeplex.com/workitem/11388
- Scheduled Tasks
Plugins and widgets cannot be enabled\disabled per store but this does not mean that their configurations cannot be made store specific. In fact this is how most of the widgets in nopCommerce 3.0 (Google Analytics for example) work. You might also be wondering if prices or specific attributes can be configure per store. Currently there is no such support and this is not even on the nopCommerce road map. Could this be achieved via customization? Please read more later in this article.
Do note that even though a category or manufacturer can be limited to a specific store, this does not mean that all products for the given category or manufacturer are automatically limited to the store. Products need to be managed separately. There is a work item to facilitate this process and you can vote for it here:
For the store owners familiar with nopCommerce, here is where you need to begin when setting your multi-store.
1. Create a website on your hosting space www.vans.bg for example and install nopCommerce on your www.vans.bg website. This is where the nopCommerce installation will run.
2. Create a second website www.etnies.bg for example and add a CNAME recrod to forward all request to your first website www.vans.bg. Do not install anything on this website, it should be empty.
3. Go back to your www.vans.bg website and configure a domain alias for www.etnies.bg.
The above three steps sound more complex than they are. Still if you have difficulties you can always ask you hosting provider or administrator to do it for you. For detailed information please read this forum post:
4. Setup your stores:
5. You do need to set the HOST VALUES for each store, because this is how nopCommerce will know which store is the active one for the current request. Read more on this later in this article:
6. Once your stores have been added you need to configure the different nopCommerce settings. Individual settings can be set for all stores or per store:
7. Once your stores and settings are configured you can start editing your catalog. Categories, products and manufactures can be limited per store as can be other entities like Blogs, News, etc...The nopCommerce administration to do this is consistent across all entity administration pages. Here is how you can limit products per store:
I bet that our developer audience, who have not looked at the nopCommerce 3.0 code yet, are wondering how all this magic works? The answer is quite simple, which can only testify to the cleverness of the nopCommerce approach.
As you could see, every store has HOST VALUES mapped to it. Therefore when a request arrives in the nopCommerce pipeline, nopCommerce inspects the HOST HEADER value of the request and sets the current store in the WebStoreContext. The WebStoreContext is available to all controllers and services, so all actions can pass the current store to data retrieval operations which require it. In the database entities (products, categories, manufacturers, etc...) are mapped to the different stores via a general table called StoreMapping.
But what you really would be using in your nopCommerce development code is the StoreMappingService in the Nop.Service.Stores namespace. The StoreMappingService has all the methods required to manage the mapping of the entities to the different stores. Most importantly it has a generic method called Authorize, which when passed an entity (a category or product for example) determines if the entity is visible in the current store.
There is one important aspect of this multi-store implementation. You can have the different stores run on different domains or subdomains, but you cannot have them run in separate virtual directories.
Earlier in this article I mentioned whether entity properties (product prices for example) can be configured per store. Currently this is not supported and because the nopCommerce architecture is not based on EAV (Entity Attribute Value) model like some other well know e-commerce systems, implementing such a configuration could be quite tricky for static properties (those that map to predefined database table columns). However nopCommerce does have a basic GenericAttribute infrastructure, which can be used for custom properties to be added to entities. Fortunately the GenericAttribute class has a StoreId property, so you can limit your custom properties to certain stores. For more information have a look at the GenericAttribute, GenericAttributeExtensions and GenericAttributeService classes.
One last thing we would like to point the attention of the nopCommerce developers to is that nopCommerce 3.0 multi-store, in fact nopCommerce itself is not multi-tenant. All stores run in the same application and app pool. Implementing a multi-tenancy in nopCommerce is not going to be a walk in the park but for those of you who are willing to tackle it, here is a good place to start:
This is our summary of the multi-store implementation in nopCommerce 3.0. In summary we can say that it is cleverly implemented, fairly easy to setup and gets the job done - provides store owners with more than one store. There is a lot to be added to this implementation but we do expect big time projects to be implemented on the initial version.
What is left to cover is how our themes and plugins are going to work with this major feature. We are going to do this in the next part of these series. Do not forget that we also have the new nopCommerce 3.0 HTML markup to talk about. So do stay tuned for more exciting nopCommerce 3.0 content!