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

ms

ms is a global object available in all stores. It is accessible in JavaScript controllers as well as in the templates.


Properties

ValueDescription
apiThis object is used to call the APIs.
cartIt contains the current cart information.
userIt contains the details of the current user.
pageIt contains the current page details.
deviceIt contains the current device information.
locationIt contains the current location information.
settingsThe property of ms global object which contains the store settings information.
variablesIt contains information about all the variables used in the store theme.
routeParams(deprecated)It contains the stateParams variable information.
preferencesIt contains the store currency and language information.
geo_locationThis property contains the geo location infomation of current user.
searchParamsIt contains the URL query parameters.
substoreIt contains the information about current substore

Methods

ValueDescription
triggerThis method triggers the specified events for the selected elements.
bindThis method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.
goToThis method sets the location of the page to the specified URL.
redirectRedirects user to the given URL. ms.redirect is search engine safe and sends a permanent redirect to the new URL.
loadScriptsThe method to load external script(s). Returns a Promise which is resolved when scripts are loaded.
loadStylesMethod to load external CSS file(s).
fetchA cross-browser implementation of fetch API

Examples

To load external script on a particular page

ms.bind("ms.page_change_success", function (event) {
     if (ms.page.name == "checkout") {
        ms.loadScripts("<url to external script>").then(function() {
             console.log("Script loaded");
        });
     }
});

Restrict store access only to logged in users

ms.bind('ms.page_change_start', function(event) {
    // Direct user to login page if a user is not logged in.
    if(!ms.user || !ms.user.isLoggedIn){
       ms.goTo('/user/login')
    }
});

Redirect user to cart summary page

<button ng-click="ms.goTo('/cart');"> Go to Cart </button>