A guide to setting up multiple stores in Magento
This post should round out my Magento focus for the last week or so. What we’re looking at doing here is setting up three different stores with three different domains all on the one framework. Magento provides support for this straight out of the box however there are a couple of points where things get a little confusing. It’s for this reason I’m publishing another guide so that people can hopefully use this to assist them along with following the official material released by the Magento developers Varien.
First up, you want to get all the easy stuff done in the admin section. Once you’re logged in, click over to your stores categories (Catalog > Manage Categories). Now create a root category for each store you’re going to setup. I’m creating three stores; Australia, UK and China and each of these stores will have products unique to it. When you are creating each category, make sure you make it “active” and that it is set to “is anchor”.

Now go to System > Manage Stores and create your stores. Each store needs to have a View, Store and Website. I’m not going to go into any detail about Views, Stores and Websites other than to say that you need to have one of each of these for each website. An example of my setup can be seen below:

With that done, we can configure each of our stores in System > Configuration. Start by selecting the Web tab and assigning a domain to each store. You can switch between stores by choosing from the Configuration Scope (shown below). Switching from one store to another allows you to set settings specific to that store.

Now you have defined the domain which is associated with each site, click on the Design tab and specify a Theme for each site. This will allow each site to look unique. Be sure to untick the “use default” box next to the “default” field or you won’t be able to edit this field.

Now our site is configured, we’re ready to dive into the tricky stuff!… but nothing too tricky.
The main idea here is that Magento needs to know how to connect the domain name with its’ specific site. This is done by just adding a few lines of code to your /index.php file.
Opening index.php in your favorite text editor will reveal a few dozen lines of code. At the bottom of this code is the following line:
-
Mage::run();
Comment this out by putting a hash infront of it, e.g.
-
#Mage::run();
Now directly underneath this, add some code to the following affect:
-
switch($_SERVER['HTTP_HOST']) {
-
// AUS
-
case 'australiashop.com':
-
case 'www.australiashop.com':
-
Mage::run('aus', 'website');
-
break;
-
-
// UK
-
case 'ukshop.com':
-
case 'www.ukshop.com':
-
Mage::run('uk', 'website');
-
break;
-
// CHINA
-
case 'chinashop.com':
-
case 'www.chinashop.com':
-
Mage::run('china', 'website');
-
break;
-
// DEFAULT (AUS)
-
default:
-
Mage::run();
-
break;
-
}
To customise this code to meet your own needs, just replace the domain names with your required domains and the shop ids with your own shop ids where in this example “china” is the shop id:
-
Mage::run('china', 'website');
Not sure what your shop ids are? Jump back into the admin area and go to System > Manage Stores. You’ve specified your shop ids in each of your websites.
And that’s it! Good luck and if you’re looking for more information, have a look at Crucial Web Hosting’s guide that helped me write this one.