Helpcenter +918010117117 https://help.storehippo.com/s/573db3149f0d58741f0cc63b/ms.settings/5256837ccc4abf1d39000001/57614ef64256dc6851749879-480x480.png" [email protected] 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

Value Description
api This object is used to call the APIs.
cart It contains the current cart information.
user It contains the details of the current user.
page It contains the current page details.
device It contains the current device information.
location It contains the current location information.
settings The property of ms global object which contains the store settings information.
variables It contains information about all the variables used in the store theme.
routeParams(deprecated) It contains the stateParams variable information.
preferences It contains the store currency and language information.
geo_location This property contains the geo location infomation of current user.
searchParams It contains the URL query parameters.
substore It contains the information about current substore

Methods

Value Description
trigger This method triggers the specified events for the selected elements.
bind This method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.
goTo This method sets the location of the page to the specified URL.
redirect Redirects user to the given URL. ms.redirect is search engine safe and sends a permanent redirect to the new URL.
loadScripts The method to load external script(s). Returns a Promise which is resolved when scripts are loaded.
loadStyles Method to load external CSS file(s).
fetch A 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>