ms is a global object available in all stores. It is accessible in JavaScript controllers as well as in the templates.
| 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 |
| 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 |
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");
});
}
});
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')
}
});
<button @click="ms.goTo('/cart')">Go to Cart</button>