Site icon MageComp Blog

How to Setup Multi Store in Magento 2 (Updated)

How to Setup Multi Store in Magento 2 Updated 2018

Every business takes a birth as one small store and starts its journey to serve more products and offering to their customers. But over the period of time to reach a wide audience, gain potential customers, improve sales and profitability one should need to expand the business to various geographic locations. It creates a necessity to have multiple stores and need to manage all store separately. Moreover, to deal better with the local audience we need to translate the store into multiple languages and respectively need to change currency too.

Having Magento 2 as rough & tough E-commerce Platform allows us to setup multi-store environment to sever purpose betterly under the hood of single Magento admin panel.

You can leverage some benefits of creating multiple store setup like…
1. Setup different customer group for each store.
2. Set different display prices as per need.
3. Category settings can be different but you can use same root category for all store views.
4. Setup a different theme for each store.
5. Set different language, currency, payment, and shipping options and apply tax classes to each store.

Simply follow these instructions and you are done!

1. Creating New Website

First Logged in to your Magento 2 admin backend. Now navigate to Stores->All Stores.

To create a new store, click on “Create Website” available on the top right corner.

Now it will require some fields like…
Name – Enter the store name
Code – Enter the code to identify store easily
Sort Order – Enter list order sequence
Set as Default – Checked to make it default store

Click “Save Web Site” after filling all the required fields.

2. Creating Store

Second step is to create the Store. From the same stores grid page click on “Create Store” button and fill the required fields.

Now it will require some fields like…
Website – Select you Magento 2 Store
Name – Enter Store frontend name
Root Category – If you want to separate catalog and products for each store, create a new category. Otherwise, select “Default Category”.

Click “Save Store” after filling all the required fields.

3. Creating Store View

Last Step is to create the Store View. On the stores grid now click on Create Store View and fill in the required fields.

Now it will require some fields like…
Store – Select your Magento 2 store
Name – Enter Store front name
Code – Enter the code to identify store easily
Status – Select option of enabled
Sort Order – Enter list order sequence

Click on “Save Store View” after filling all the required fields.

Now, let’s check that store is created successfully or not? Go to stores->Configuration and open drop down menu from default config and see store is liste or not! Now select the store we have just created minutes ago from the list.

4. Store base Url Setup

Now we need have to assign base URL to our newly created second store. For that go to Stores->Configuration->General tab-> Web.

Now we can set URLs using any of these two methods.

Repeat the same steps for the Base URL (Secure) section and Save Config at last.

Once you’re done with creating a store, you need to configure the server to load it properly on the frontend. There are two popular methods for it, use any of them.

Method 1: Separate directories for each store using secondary domains

    1. Check if your desired domain name points to the server. Create a secondary domain for your new store.
    2. Either use FTP or SSH and copy the .htaccess and index.php files from your Magento to the document root of your new domain.
    3. Open copied index.php file and edit the last lines of the file as follows:
      Replace following code:
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

/** @var \Magento\Framework\App\Http $app */
$app = bootstrap->createApplication('Magento\Framework\App\Http');

$bootstrap->run($app);

With the below code:

require __DIR__ . '/app/bootstrap.php';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ' [WebsiteCode]';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
  1. Create symbolic links in the document root of your new domain using SSH, and replace the path given below with the full path:
ln -s /home/[user_name]/demo.com/html/app/ app 
ln -s /home/[user_name]/demo.com/html/lib/ lib 
ln -s /home/[user_name]/demo.com/html/pub/ pub 
ln -s /home/[user_name]/demo.com/html/var/ var 

Once you have successfully configured your secondary domain to work with Magento, The new domain will load in browser and you can begin developing new store.

Method 2: Shared directory for all stores using pointer domains

    1. Verify your desired domain name is pointing to the server.
    2. Create a server alias pointer domain for your new store. The pointer domain will be pointing at the primary domain of your Magento installation.
    3. Edit .htaccess file in the document root of your Magento installation and enter the following code just above the line RewriteEngine On:
      • Replace .*newstore.* with the domain of your new created store, keep the dots and asterisks as it is.
      • Make sure that MAGE_RUN_CODE matches with the code you wrote down when you created the new website with above steps. Here, newstore specifies the domain name and websitecode specifies the store code created in Magento.
SetEnvIf Host .*[StoreCode].* MAGE_RUN_CODE=[StoreCode]
SetEnvIf Host .*[StoreCode].* MAGE_RUN_TYPE=website or store
  1. Once you have successfully configured your pointer domain to work with Magento, you’re ready to develop new store.

If you want separate catalog and products for each store

From sidebar menu, navigate to Products->Categories.

Now click on “Add Root Category”.

Provide a name to category and activate it by selecting “Yes” from dropdown.

Now move to “Display Settings” and set “yes” to the option “Is Anchor”.

Becuase now you have learned to create a store, you can create one or more store according to your need of setting up different languages and currencies. Comment down below if you are facing an issue while creating store.
Feel free to ask questions regarding this code.
Happy Setting Up!

Exit mobile version