Latest Blog - Magento

  • Industry : Magento
  • Timeline : Oct 25, 2016
  • Writer : Arpatech Website

How to Configure Multiple Stores in Magento 2

Being one of the most powerful ecommerce platform in the industry, Magento boasts a stellar reputation because of its fluid functionality and secure infrastructure. And in this article we will discuss about how to configure multiple stores in Magento 2. So, we are all well-aware of the fact that there are many features which are launched by Magento from time to time. Multistore function is one of the features in Magento 2 which is for the merchants and developers. Magento 2 also provides you with the facility to setup multiple stores which you must have used in Magento 1 as well. But since we know that Magento 2 is absolutely different than the previous versions, it is a little difficult to manage features in it for those peoples who have just started doing development in Magento 2. This is because of the advancements that been made in the file system. So, without further ado, I’ll teach you the complete store configuration in Magento 2, so that you can further configure multiple stores in Magento 2 like a boss:

Let’s Begin:  

When you want to create a second store in Magento 2, you have to go to the Admin dashboard of your Magento 2 store and from there follow this path Stores/ Settings / All Storesimage08

  • There are three options present under “All Stores” which you can see as “Create Website”, “Create Store View”, “Create Store”. The first thing you have to do is to click on the ‘Create Website’ Button.

image02

  • Now you have to enter the name of your second store in the Name field.
  • Then enter your second store’s code name in the code field. (Make sure you remember your second store’s code)

image01

  • Next, for your second store’s website you have to click on ‘Create Store.’

image04

  • Go in the “Web Site” option and select your website for your Magento 2 Store.
  • Go in the “Name” field and enter the view name.
  • Go in the “Root Category” there select “Default Category” and then click on the “Save Store” button.

image03

  • Once you have created your store, you now have to create the store view for your second store for Magento 2. Now Select and click on “Create Store View”

image06

  • Go in the“Store” field and Select your Magento 2 store
  • Go in the “Name” field and then you have to enter your Store View Name
  • Go in the “Code” field and enter the code which you previously entered in “Create Website”

image05

  • Once you have done this, now click on “Save Store View” button. After completing this step you can now connect your second store domain with the new store that you have just created. Now follow this path Stores > Settings > Configuration
  • In “Configuration” click on your second store by selecting the option in “Store View”, it will be similar to what you can see in the top image.

image07If you’ve followed the Magento 2 store configuration we’ve mentioned above, you must have successfully created your second store in Magento 2. Next you have to set values for MAGE_RUN_TYPE and MAGE_RUN_CODE which you can do by applying the following code in your index.php entry point:

<?php
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'yourcode.yourdomain.com';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
?>

Now make sure you Save your index.php file. After doing this you have to set the values in .htaccess file. This section here discusses the process through which you can set values for MAGE_RUN_TYPE and MAGE_RUN_CODE for using Apache Server Variables SetEnvIf or RewriteCond. To setup SetEnvIf, you have to add the following in your .htaccess file after “RewriteEngine on” this:

SetEnvIf Host .*example.com.* MAGE_RUN_CODE=yourcode.yourdomain.com
SetEnvIf Host .*example.com.* MAGE_RUN_TYPE=website

To setting up RewriteCond, you should add the following code in your .htaccess file after “RewriteBase /magento/” This:

RewriteCond %{HTTP_HOST} ^(.*)example\.com
RewriteRule .* – [E=MAGE_RUN_CODE:yourcode.yourdomain.com]
RewriteCond %{HTTP_HOST} ^(.*)example\.com
RewriteRule .* – [E=MAGE_RUN_TYPE:website]

Now again Save your .htaccess file.

Conclusion

Congratulations! Now you have successfully configured multiple stores in Magento 2 and you can get started with it. I suggest since you’ve worked so hard configuring it, it’s integral that you host it on a secure and best ecommerce hosting platform. So that you get the best security, and your cart’s abandonment ratio remains below the danger zone at all times. So, let us know which hosting platform you are using for your ecommerce business in the comment section below and if you’re satisfied with it.

More Articles by Arpatech

Design

design for business
logo design
problem-solving web design
ui/ux
product design

Art

motion design
branding
illustration
icons
logo design

AI

machine learning
deep learning
theory of mind
expert system

Development

web development
app development
software development

Apps

app design
usability
mobile app
animations