This is a free translation of
this article . The article is intended for people familiar with Magento, so many of the basic things from the original article have been omitted. There are several implementations for solving this problem:
- As subdirectories of the main site, for example,
- mall.com/shoes
- mall.com/shirts
- Using different domain names, for example,
- Using subdomains of the main site, for example,
- mall.com
- shoes.mall.com
- shirts.mall.com
As a result, there will be several stores using the same code and managed from the same admin panel.
Adding another store to Magento
First you need to create a root category for the new store, make it active and set the value of the
Is Anchor attribute to
Yes . Next, go to the
System -> Manage Stores admin section and create a new
Website ,
Store and
Store View . More on the example:
Website:Store:- Name - Main Store
- From the list of Website choose 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 section
System -> Configuration .
Current Configuration Scope (located on the upper left) 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 2nd level domain names http://shoes.com/
- For 3rd level domain names http://shoes.mall.com/
The trailing slash in each URL is required.
')
In order to be able to access these URLs, you need to do the following:
Subdirectories
So, we need our store to be in the subdirectory of the main site.
To do this, you need to 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 file
index.php . We are looking 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' . You also need to add two parameters to the
Mage :: run () method call.
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:
Domain names
Since, in fact, we will have several domain names tied to one server on which Magento is installed, we will have to edit the original index.php file. So, replace the string
Mage :: run ();on
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
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 ;
- }
In general, 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 subdomain shoes.mall.com. I hope that everything necessary for the configuration of the subdomain has already been done on the hosting, so let's move on to creating a store on this subdomain.
As at the stage with subdirectories, you need to copy the .htaccess and index.php files from the Magento root directory to the subdomain root directory, after which you can start editing the
index.php file. The first thing to do is to indicate in the
index.php file where to lay the Mage.php file. So, replace in the file
index.php , line
$ mageFilename = 'app / Mage.php';on
$ mageFilename = '../public_html/app/Mage.php';This path may be different for you; it all depends on the location of the domain directories on your hosting, which is relative to each other.
Next, you need to replace the code
Mage :: run () with
Mage :: run ('shoes', 'website') so that the Magento engine knows which store to run. And the last thing to do is to 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 managed by the same installed system with any content, i.e. The content of these stores can be related to each other, or have nothing in common. Everyone can use the method that is more convenient for him, the result will ultimately be identical. The main advantage here is the convenience of managing several stores and saving time for store managers.