100 Views

Every business starts small, often as a single store, and aims to grow by offering more products to its customers. As time goes on, businesses need to expand to reach a wider audience, attract more customers, and increase sales and profits. This often involves opening multiple stores in different locations. To connect with local customers, businesses may need to offer their store in various languages and currencies.

Magento 2 is a robust e-commerce platform that allows you to set up a multi-store environment. This lets you manage different stores from a single Magento admin panel, making it easier to handle various needs.

Here are some benefits of creating a multi-store setup with Magento 2:

  1. Create different customer groups for each store.
  2. Set different prices for each store as needed.
  3. Use different category settings while sharing the same root category across all store views.
  4. Apply a unique theme to each store.
  5. Set different languages, currencies, payment, and shipping options, and apply tax classes to each store.

1. Creating a New Website

First, log in to your Magento 2 admin backend. Then navigate to Stores -> All Stores.

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

Now you’ll need to fill out some fields:

  • Name: Enter the name of the store.
  • Code: Enter a code to easily identify the store.
  • Sort Order: Enter the order in which the store should appear in the list.
  • Set as Default: Check this box if you want to make it the default store.

After you’ve filled in all the required fields, click “Save Web Site.”

2. Creating a Store

The next step is to create the store. From the same stores grid page, click the “Create Store” button and fill in the required fields.

Now you’ll need to fill in the following fields:

  • Website: Select your Magento 2 store.
  • Name: Enter the name that will be displayed on the store’s front end.
  • Root Category: If you want to have a separate catalog and products for each store, create a new category. If not, select “Default Category.”

Once you’ve completed all the fields, click “Save Store.”

3. Creating a Store View

The final step is to create the Store View. On the stores grid page, click “Create Store View” and fill in the necessary fields.

When creating a new store view, you’ll need to complete the following fields:

  • Store: Select the Magento 2 store for which you want to create a store view.
  • Name: Enter the name that will appear on the store’s front end.
  • Code: Provide a unique code to easily identify the store.
  • Status: Choose the “Enabled” option to activate the store view.
  • Sort Order: Specify the order in which this store view should appear in lists.

After completing these fields, click “Save Store View.”

Next, let’s verify that the store has been created successfully. Go to Stores -> Configuration, open the dropdown menu from “Default Config,” and check if your new store is listed. Select the store you just created from the list.

4. Store Base URL Setup

Now, we need to assign a base URL to our newly created store. To do this, navigate to Stores -> Configuration -> General tab -> Web.

You can set the URLs using one of these two methods:

  1. Using the Main Store URL: Check the “Use Default” box.
  2. For a Specific Store URL: Go to the Base URL field and enter the URL, making sure to include a “/” at the end.

Repeat these steps for the “Base URL (Secure)” section and click “Save Config” once finished.

Once you’ve created the store, you’ll need to configure the server to ensure it loads properly on the front end. You can use one of these popular methods:

Method 1: Separate Directories for Each Store Using Secondary Domains

  1. Ensure that your desired domain name points to the server. Create a secondary domain for your new store.
  2. Use FTP or SSH to copy the .htaccess and index.php files from your Magento installation to the document root of your new domain.
  3. Open the copied index.php file and edit the last lines as follows:

    Replace this code:

    php

    $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 this code:

    php

    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);
  4. Create symbolic links in the document root of your new domain using SSH, replacing the path with the full path to your Magento installation:
    bash

    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, your new domain will load in the browser, and you can begin developing your new store.

Method 2: Shared Directory for All Stores Using Pointer Domains

  1. Verify that your desired domain name points to the server.
  2. Create a server alias pointer domain for your new store. This pointer domain should point to the primary domain of your Magento installation.
  3. Edit the .htaccess file in the document root of your Magento installation, adding the following code just above the line RewriteEngine On:
    apache

    SetEnvIf Host .*newstore.* MAGE_RUN_CODE=[StoreCode]
    SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=website or store
    • Replace .*newstore.* with the domain of your newly created store, keeping the dots and asterisks as they are.
    • Ensure that MAGE_RUN_CODE matches the code you used when creating the new website. Here, newstore specifies the domain name, and websitecode specifies the store code created in Magento.

Once your pointer domain is configured to work with Magento, you’re ready to develop your new store.

If You Want Separate Catalog and Products for Each Store

  1. From the sidebar menu, navigate to Products -> Categories.
  2. Create a new root category if needed, and set up categories and products for each store individually.

This setup will allow you to manage multiple stores efficiently under one Magento installation, providing flexibility and control over your e-commerce operations.

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”.

Now that you’ve learned how to create a store in Magento 2, you can set up multiple stores to meet your needs, such as offering different languages and currencies. This flexibility helps you cater to various markets and improve your customers’ shopping experience.

If you encounter any issues while creating a store, please leave a comment below. I’m here to help with any questions or concerns you might have about this process. Don’t hesitate to reach out if you need further assistance or clarification. Happy store building!