Config

Read the store, customer and page data the SDK started with, and check whether the customer is logged in.

Read this when browser code needs a value the SDK holds, such as the store id, the current page or whether the customer is logged in.

When the engine starts the SDK, it hands it the store's settings, the customer and the current page. Salla.config keeps them. In React components, read the same data from the hooks first: useStore, useTheme and useUser. Use Salla.config in SDK code, in event handlers, and for values the hooks do not expose.

Read a value

Pass a key. Use dots for nested values, and an optional default:

Salla.config.get('store.id');                 // 1305146709
Salla.config.get('page.slug');                // 'product.single'
Salla.config.get('user.currency_code', 'SAR');
Salla.config.all();                           // the whole object

Some keys you will use:

KeyHolds
store.id, store.urlThe store's id and address
store.featuresFeature flags the store has on, such as 'loyalty-system'
user.id, user.typeThe customer, and 'user' when logged in
user.currency_code, user.language_codeThe customer's chosen currency and language
page.slug, page.idThe kind of page and its product, category or order id
currenciesThe store's currencies by code, each with code, name and symbol
theme.is_rtlWhether the page is right-to-left

The engine sets page again after each navigation in the browser, from the page your route's loader returns. The built-in routes all return one, so there page.slug matches the page on screen.

Check the customer

MethodReturns
Salla.config.isUser()true when the customer is logged in
Salla.config.isGuest()true when they are not

Many SDK methods need a logged-in customer. The wishlist methods, for example, open the login popup for a guest instead of sending the request.

Currencies and languages

MethodReturns
Salla.config.currency(code?)One currency (code, name, symbol). Without a code, the customer's chosen one.
Salla.config.currencies()A promise of all currencies by code. It loads the list from the store once.
Salla.config.languages()A promise of the store's languages, each with code, url and is_rtl.

To show prices, use useMoney in components. It formats with the right currency for you.

Change a value

Salla.config.set(key, value) changes one value, with dots for nested keys:

Salla.config.set('debug', true);  // the SDK logs what it does to the browser console

To change several top-level values at once, use Salla.config.merge({ ... }).

Gotchas

  • set takes a key and a value. Salla.config.set({ debug: true }) throws: pass an object to merge instead.
  • set changes only the SDK's copy. Your React state and the hooks do not see it.
  • For a top-level key such as 'debug', get also returns the default when the value is empty (0, '', false). A dotted key returns the default only when the value is missing.
  • currencies() and languages() load the list once per page. Later calls return the same list.

See also

On this page