How to Setup Magento 2 Website Switcher?

How to Setup Magento 2 Website Switcher?
Magento is one of the most preferred and liked platforms for eCommerce sites that empowers thousands of retailers & brands across the globe. The platform offers greater scalability, security and performance. One of the most appealing features in Magento 2 is that you can create new websites, stores, store views and configure them for specific regions. This is a relatively complex job and beginners may find it difficult to configure multiple websites, stores, store views and setting up their URLs. So here we are to provide a step by step tutorial to help you do this.

The Purpose of Creating Store Switcher & Website Switcher in Magento 2

Creating multiple websites, merchants can showcase products and services in various categories on the website with different checkout & shipping methods. Use the Store Switcher extension by FME in order to add an auto store switcher functionality to your Magento 2 website.

Buy Extension

Follow the steps below to setup multiple websites, stores & store views in Magento 2.

Create Websites

In order to add Magento 2 website switcher functionality, you need to create websites by following these steps:
  • Log in to the Magento Admin Panel with an account authorized to create websites, stores, and store views.
  • Click Stores > Settings > All Stores
  setup-new-website-switcher-in-magento-2
  • On the Stores page, click Create Website
  setup-website-switcher-in-magento-2   Once the page loads, fill in the following required fields.
  • Name - Enter website name
  • Code - Enter a unique code to identify the website, e.g. German website
  • Sort Order - Set website sort order.
  • Click Save Web Site
  configure-website-switcher-in-magento-2  

Create Stores

Each Website must have at-least one store. In order to create a store, follow these steps:
  • In the Magento Admin panel, click Stores > Settings > All Stores
  • On the Stores page, click Create Store.
  create-store-switcher-in-magento-2   Once the page loads, fill the required fields.
  • Website - If you have multiple websites, then choose the website with which you want to associate this store
  • Name - Enter Store name
  • Code - Enter a unique code for each store
  • Root Category - If you’re having multiple root categories, select a root category for this store.
  configure-store-switcher-in-magento-2 NOTE: Create a unique root category, if you want to have unique root category for each store/website.

Create Store View

Each store must have a store view. In order to create a store view, follow these steps:
  • In Magento Admin panel, click Stores > Settings > All Stores.
  • On the Stores page, click Create Store View.
  create-store-view-in-magento-2   Once the page loads, fill the required fields.
  • Store - If you have multiple stores, then choose the store with which you want to associate this store view.
  • Name - Enter store view name, e.g. german store view
  • Code - Enter a unique code for each store view, e.g. de for german store view
  • Sort Order - Set store view sort order.
  • Click Save Store View
  configure-store-view-in-magento-2  

Change the Website Base URL

To access a website using a unique URL like https://german.fmeplugins.net, you must change the Base URL for each website in the Magento Admin Panel.

To change the Website Base URL, follow these steps:

  • Open Magento Admin panel, click Stores > Settings > Configuration
  • Now Click General > Web
  • From the Store View list at the top of the page, click the name of one of your websites as shown below.
  setup-website-switcher-base-url-in-magento-2   Once the page loads, Click Base URLs section
  • In the Base URLs section, Uncheck the Use Default
  • Enter the URL in the Base URL and Base Link URL fields. E.g https://german.fmeplugins.net/ or https://example.com/magento/
  • Now Repeat the above steps for the Base URLs (Secure) section as well
  • Click Save Config
  setup-website-switcher-base-url-in-magento-2

Change the Default Store View Base URL

  • Open Magento Admin panel, click Stores > Settings > Configuration
  • Now Click General > Web
  • From the Store View list at the top of the page, click the Default Config
  setup-website-switcher-base-url-in-magento-2 Once the page loads, Click Base URLs section
  • In the Base URLs section, Uncheck the Use system value
  • Enter the Base URL in the Base URL and Base Link URL fields
  • Now Repeat the above steps for the Base URLs (Secure) section
  • Click Save Config
  setup-website-switcher-base-url-in-magento-2  

Add the Store Code to the Base URL

  • On the Admin sidebar, Click Stores. Then under Settings > choose Configuration
  • In the left panel, Click & Expand General > Click Web
  • From the Store View dropdown menu at the top of the page, Select Default Config
  • Expand the URL Options section
  • Uncheck the Use System Value against Add Store Code to Urls field
  • Set Add Store Code to YES and Click Save Config
  add-store-switcher-code-to-base-urls-in-magento2  

Once configuration is saved, a prompt message will appear to flush cache

.

Flush Magento 2 Cache:

  • To Flush Magento cache, Click System > Cache Management on Admin sidebar.
  • Once Cache Management page loads, Click Flush Magento Cache button on right top bar.

URL with Store Code - http://www.yourdomain.com/magento/[store-code]/index.php/url-identifier

URL without Store Code - http://www.yourdomain.com/magento/index.php/url-identifier

For more information regarding Store Base URLs, see the Magento User Guide

.

How to Add Auto Store Switcher in Magento 2 Website?

GeoIP Auto Store Switcher for Magento 2

In order to automate this process, I would recommend to use Magento 2 GeoIP Default Store Switcher Extension, which enables you to create & configure multiple stores for different countries or regions. This extension automatically detects the visitor location from their IP address and redirect them to the region optimized store. Visitors can also manually switch to another store from the store switcher popup at the footer of the homepage.

Key Features:

  • Redirect Users to Relevant Store Based on Their Location
  • Create Rules, Select Countries & Assign Stores to Diff. Countries
  • Automatically Detects Visitors’ Locations by IP Address
  • Setup Manual or Automatic Redirection
  • Provide the IPs List to Exempt from Store Switching Rule

Configure Auto Store Switcher in Magento 2

You can now configure and personalize a store for a specific country or region once you have created stores, store views & installed GeoIP Store Switcher extension for Magneto 2. For this you need to create a store switching rule.

Creating a Store Switching Rule

From Admin Sidebar Tap FMEextensions > Click Manage GeoIP Default Store Once GeoIP Default Store Information page loads, enter the following information;
  • Title – Set title of the rule, e.g for redirecting European visitors to European store view, etc.
  • Priority – Set priority of the store switcher rule
  • Store Group – Select a store that you have created
  • Status – Enable/Disable the Store Switcher rule
  • IP Exceptions - Enter specific IP addresses to white-list/overrule the store switcher rule
  • Description – Enter description of the store switcher rule
  • Now on left side, click Countries tab, here you can select a country or countries that you want to redirect its visitors to the selected store
  • Click Save Rule
  magento-2-store-switcher NOTE: You can update the country list by importing a latest Maxmind database.

Store Switcher Extension Configurations:

  • You can Enable/Disable the Store Switcher Extension
  • Auto Redirect - If Enabled, the visitor will be redirected to the assigned store automatically & if Disabled, a store switcher popup will be prompted. Visitors can manually select a store.
  • Popup Title - Enter Popup title
  • Popup Button Text - Enter Text for Popup button, e.g. continue, enter, etc.
  7-GEOIP-Default-Store-Switcher-Extension
  • Import Countries List - This extension uses Maxmind Country IP database for Geo Information. You can download the latest Maxmind database here and upload it at the Magento Admin panel.
  import-maxmind-database-magento-2