How to create multiple stores using one Magento installation
This is a free translation of this article . The article is intended for people familiar with Magento, so many basic things from the original article were omitted. There are several implementations of solving this problem:
The result will be several stores that use the same code and are managed from the same admin panel.
First you need to create the root category for the new store, make it active and set the value of the Is Anchor attribute to Yes . Next, go to the admin section of the System -> Manage Stores and create new Website , Store and Store View . More details on the example:
Website:
Store:
Store View:
Additional stores are created similarly.
Now you need to specify the base URLs for the new store. Go to the System -> Configuration section . Current Configuration Scope (located at the upper left) we change the Default Config value to Shoes . On the Web tab in the Secure and Unsecure sections, specify the Base URL . For each case, this URL will be different, for example:
A trailing slash in each URL is required.
In order to be able to access these URLs, you need to do the following:
So, we need our store to be in the subdirectory of the main site.
To do this, create a shoes subdirectory in the root of Magento and copy the .htaccess and index.php files from the Magento root directory there. Then you need to edit the index.php file . We search for the line $ mageFilename = 'app / Mage.php' and specify the correct path to the Mage.php file . In this case, it is $ mageFilename = '../app/Mage.php' . It is also necessary to add two parameters to the call to the Mage :: run () method .
We fix
Mage :: run ();
on
Mage :: run ('shoes', 'website');
After that, you can contact the Shoes store at http://mall.com/shoes/.
This part is explained in great detail in the following 2 videos:
Since, in fact, we will have several domain names associated with the same server on which Magento is installed, we will have to edit the original index.php file already. So, replace the line
Mage :: run ();
on the
For more stores, you need to change the code as follows:
That's all. After these manipulations, the store will be available at http://shoes.com/.
We have the main domain mall.com, we need to raise the 2nd store on the shoes.mall.com subdomain. I hope that everything necessary for configuring the subdomain has already been done on the hosting, so let's move on to creating a store on this subdomain.
As in the step with the subdirectories, you need to copy the .htaccess and index.php files from the Magento root directory to the root directory of the subdomain, after which you can start editing the index.php file . The first thing to do is to indicate in the index.php file where the Mage.php file is located . So, in the index.php file, replace the line
$ mageFilename = 'app / Mage.php';
at
$ mageFilename = '../public_html/app/Mage.php';
You may have a different path, it all depends on the location of the domain directories on your hosting regarding each other.
Next, you need to replace the code Mage :: run () with Mage :: run ('shoes', 'website') so that the Magento engine knows which store needs to be launched. And the last thing to do is create symbolic links to all the main Magento directories:
Now the store will be available at http://shoes.mall.com/.
As a result, we get several stores controlled by one installed system with any content, i.e. the content of these stores may be interconnected or have nothing in common. Everyone can use the method that is more convenient for him, the result, in the end, will be identical. The main advantage here is the convenience of managing several stores and saving time for store managers.
- As subdirectories of the main site, for example,
- mall.com/shoes
- mall.com/shirts
- Using different domain names, for example,
- shoes.com
- shirts.com
- Using subdomains of the main site, for example,
- mall.com
- shoes.mall.com
- shirts.mall.com
The result will be several stores that use the same code and are managed from the same admin panel.
Adding another store to Magento
First you need to create the root category for the new store, make it active and set the value of the Is Anchor attribute to Yes . Next, go to the admin section of the System -> Manage Stores and create new Website , Store and Store View . More details on the example:
Website:
- Name - Shoes
- Code - shoes
Store:
- Name - Main Store
- From the Website list, select Shoes
- From the list, the Root Category selects the root category created earlier.
Store View:
- From the Store list, select Main Store
- Name - English (not important, you can write anything)
- Code - shoes_en
- Status - Enabled
Additional stores are created similarly.
Now you need to specify the base URLs for the new store. Go to the System -> Configuration section . Current Configuration Scope (located at the upper left) we change the Default Config value to Shoes . On the Web tab in the Secure and Unsecure sections, specify the Base URL . For each case, this URL will be different, for example:
- Subdirectories - http://mall.com/shoes/
- For Level 2 Domain Names http://shoes.com/
- For 3rd level domain names http://shoes.mall.com/
A trailing slash in each URL is required.
In order to be able to access these URLs, you need to do the following:
Subdirectory
So, we need our store to be in the subdirectory of the main site.
To do this, create a shoes subdirectory in the root of Magento and copy the .htaccess and index.php files from the Magento root directory there. Then you need to edit the index.php file . We search for the line $ mageFilename = 'app / Mage.php' and specify the correct path to the Mage.php file . In this case, it is $ mageFilename = '../app/Mage.php' . It is also necessary to add two parameters to the call to the Mage :: run () method .
We fix
Mage :: run ();
on
Mage :: run ('shoes', 'website');
After that, you can contact the Shoes store at http://mall.com/shoes/.
This part is explained in great detail in the following 2 videos:
- http://www.magentocommerce.com/magento-on-the-fly/multiple-sites/
- http://www.magentocommerce.com/magento-on-the-fly/multiple-sites2/
Domain names
Since, in fact, we will have several domain names associated with the same server on which Magento is installed, we will have to edit the original index.php file already. So, replace the line
Mage :: run ();
on the
- switch($_SERVER['HTTP_HOST']) {
- case 'shoes.com':
- case 'www.shoes.com':
- Mage::run('shoes', 'website');
- break;
- default:
- Mage::run();
- break;
- }
For more stores, you need to change the code as follows:
- switch($_SERVER['HTTP_HOST']) {
-
- // Shoes.com
- case 'shoes.com':
- case 'www.shoes.com':
- Mage::run('shoes', 'website');
- break;
-
- // Hats.com
- case 'hats.com':
- case 'www.hats.com':
- Mage::run('hats', 'website');
- break;
-
- // Shirts.com (default store)
- default:
- Mage::run();
- break;
- }
That's all. After these manipulations, the store will be available at http://shoes.com/.
Subdomains
We have the main domain mall.com, we need to raise the 2nd store on the shoes.mall.com subdomain. I hope that everything necessary for configuring the subdomain has already been done on the hosting, so let's move on to creating a store on this subdomain.
As in the step with the subdirectories, you need to copy the .htaccess and index.php files from the Magento root directory to the root directory of the subdomain, after which you can start editing the index.php file . The first thing to do is to indicate in the index.php file where the Mage.php file is located . So, in the index.php file, replace the line
$ mageFilename = 'app / Mage.php';
at
$ mageFilename = '../public_html/app/Mage.php';
You may have a different path, it all depends on the location of the domain directories on your hosting regarding each other.
Next, you need to replace the code Mage :: run () with Mage :: run ('shoes', 'website') so that the Magento engine knows which store needs to be launched. And the last thing to do is create symbolic links to all the main Magento directories:
ln -s ../public_html/404/ ./404
ln -s ../public_html/app/ ./app
ln -s ../public_html/includes/ ./includes
ln -s ../public_html/js/. / js
ln -s ../public_html/media/ ./media
ln -s ../public_html/report/ ./report
ln -s ../public_html/skin/ ./skin
ln -s ../public_html/var / ./var
Now the store will be available at http://shoes.mall.com/.
As a result, we get several stores controlled by one installed system with any content, i.e. the content of these stores may be interconnected or have nothing in common. Everyone can use the method that is more convenient for him, the result, in the end, will be identical. The main advantage here is the convenience of managing several stores and saving time for store managers.