Skip to content

General services

Michal7Cohen edited this page Apr 22, 2019 · 7 revisions

As part of your theme development process, and in order to make development easier, you are given access to services provided by uStore.

All services are located under the ustore-internal folder. You should not make any changes to the content of this folder. Make sure to use the service without touching the code.

Services

themeContext – Exposes the theme’s current state:

  • languageCode – Language code as shown in the URL (i.e. en-US).
  • storeFriendlyID – Friendly ID of the current store.
  • storeID – GUID of the current store.
  • page – Currently displayed page, i.e Home, Category, Cart.
  • classicUrl – URL of uStore legacy store.
  • securityToken - Token used for the API calls.

utils – General utilities in the application:

  • getCookie - Get cookies from the browser.
  • deleteCookie – Delete cookies by name.
  • setCookie – Set cookies in the browser by key and value.

urlGenerator – Enables to generate store URLs.
You can use it in the tag in order to redirect to another page in the store.

For example:

<Link to={urlGenerator.get({page:'category', id:12})}>	

The get function of this service can receive two parameters: page (mandatory) and Id (optional). The page parameter is the page name. The page name must be in kebab case (i.e. products-list), as opposed to the page’s name in the routes folder, which uses pascal case (i.e. ProductsList).

The second parameter is the Id of the page, and in this example it is the category Id.
If you wish to get the Id of the current page, do so by using the themeContext service:

contextService.getValue("id")

The following is the return value of the above example: image

Clone this wiki locally