currency

List the store's currencies and switch the customer to another one.

Use Salla.currency when the customer picks the currency prices are shown in. The salla-localization-modal web component lets them pick language and currency, and the engine's default header already includes it: see salla-localization-modal.

await Salla.currency.change('USD');
window.location.reload(); // prices on the page are still in the old currency

Methods

MethodParametersDoes
listnoneThe store's currencies, each with code, name and symbol
changecode or { currency }Switches the customer to that currency

Salla.config.currencies() gives the same list by code and loads it only once. See Config.

After a change

change saves the choice and forgets the saved cart summary, so the next cart request comes back in the new currency. It does not touch what is already on the page. Reload, as the localization modal does, so every loader runs again with the new currency. This is the one case where a full reload is right: every price on the page changes at once.

To open the modal on its currency list from your own button, dispatch Salla.event.dispatch('currency::open').

Events

EventFires whenArguments
currency::changed / currency::failedchangeresponse or error, currency code
currency::fetched / currency::failed.to.fetchlistresponse or error

Gotchas

  • change with no code rejects at once with "Can't find currency code!".
  • Show prices with useMoney, which formats in the customer's chosen currency.

See also

On this page