Helpcenter +918010117117 https://cdn1.storehippo.com/s/573db3149f0d58741f0cc63b/ms.settings/5256837ccc4abf1d39000001/57614ef64256dc6851749879-480x480.png" support@storehippo.com https://www.facebook.com/StoreHippohttps://twitter.com/StoreHippohttps://www.linkedin.com/company/hippoinnovations/https://plus.google.com/+Storehippo/posts
B4,309-10 Spaze iTech Park, Sector 49, Sohna Road, 122001 Gurgaon India
call to replace anchor tags contains '/admin' in href

Functionality to remember the user selected substore

StoreHippo allows you to set up the functionality to remember the user-selected substore. This functionality allows your store to remember the previously selected substore of the particular user.

Scenario

Suppose your store has three substores, which are Substore1, Substore2, and Substore3. Now, if any particular user has selected Substore2, you want Substore2 to be pre-selected whenever that user visits the site.

Steps

To achieve this, follow the steps given below:

  • Go to the Site > Startup Widgets section of the StoreHippo Admin Panel.
  • Click the Add New button.
  • In the Name field, provide the name of the startup widget.
  • Paste the following code in the Controller section as shown in the image below.
ms.bind('ms.page_loaded', function (event) {
    if (ms.substore && ms.substore.alias) {
        localStorage.setItem("substore", ms.substore.alias)
    }
    if (ms.substore || !localStorage.getItem("substore") || !localStorage.getItem("substore").length) {
        return;
    }
    var req = {
        entity: 'ms.settings',
        customCommandName: '',
        data: {
            "store": localStorage.getItem("substore")
        }
    }
    ms.app.call('setPreferences', req, function (err, response) {
        if (!err) location.reload();
    })
})

  • After adding the controller code, click the Save button to apply the changes.

Now, the store which was selected by the user previously will be auto-selected.

Share:

2021-01-08T07:20:00.558Z