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 objectSome keys you will use:
| Key | Holds |
|---|---|
store.id, store.url | The store's id and address |
store.features | Feature flags the store has on, such as 'loyalty-system' |
user.id, user.type | The customer, and 'user' when logged in |
user.currency_code, user.language_code | The customer's chosen currency and language |
page.slug, page.id | The kind of page and its product, category or order id |
currencies | The store's currencies by code, each with code, name and symbol |
theme.is_rtl | Whether 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
| Method | Returns |
|---|---|
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
| Method | Returns |
|---|---|
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 consoleTo change several top-level values at once, use Salla.config.merge({ ... }).
Gotchas
settakes a key and a value.Salla.config.set({ debug: true })throws: pass an object tomergeinstead.setchanges only the SDK's copy. Your React state and the hooks do not see it.- For a top-level key such as
'debug',getalso returns the default when the value is empty (0,'',false). A dotted key returns the default only when the value is missing. currencies()andlanguages()load the list once per page. Later calls return the same list.