📜 ⬆️ ⬇️

How to create multiple stores using one installation Magento

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 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:

Store View:

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:

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
  1. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  2. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  3. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  4. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  5. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  6. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  7. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  8. switch ($_SERVER[ 'HTTP_HOST' ]) { case 'shoes.com' : case 'www.shoes.com' : Mage::run( 'shoes' , 'website' ); break ; default : Mage::run(); break ; }
  9. 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:
  1. switch ($ _SERVER [ 'HTTP_HOST' ]) {
  2. // Shoes.com
  3. case 'shoes.com' :
  4. case 'www.shoes.com' :
  5. Mage :: run ( 'shoes' , 'website' );
  6. break ;
  7. // Hats.com
  8. case 'hats.com' :
  9. case 'www.hats.com' :
  10. Mage :: run ( 'hats' , 'website' );
  11. break ;
  12. // Shirts.com (default store)
  13. default :
  14. Mage :: run ();
  15. break ;
  16. }

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.

Source: https://habr.com/ru/post/91611/


All Articles