Frontend API
Methods to format money, and handle currency selection and conversion when multi-currency is enabled.
Returns a formatted string based on store currency settings.
This method will automatically use the store's base currency settings by default, or the selected currency in a multi-currency setup.
swell.currency.format(10) // => $10.00
Optionally override default currency settings:
swell.currency.format(10, {
code: 'EUR',
locale: 'en-GB'
decimals: 4, // number of decimal digits
rate: 0.8874 // conversion rate
}) // => €8.874
Returns an array of enabled currencies. Result will be empty if multi-currency has not been configured on the store.
await swell.currency.list()
[
{
"code": "USD",
"rate": 1,
"name": "US Dollar",
"symbol": "$",
"decimals": 2,
"type": "base"
},
{
"code": "EUR",
"rate": 0.82542,
"name": "Euro",
"symbol": "€",
"decimals": 2,
"type": "display"
},
{
"code": "AUD",
"rate": 1.28934,
"name": "Australian Dollar",
"symbol": "A$",
"decimals": 2,
"type": "display"
}
]
Sets a browser cookie and updates the user's session and cart to the selected currency.
In a multi-currency setup, call the select() method to change settings used by format() to render money values.
If a cart exists in the user's session, this method also updates the cart to reflect the user's currency preference.
await swell.currency.select('EUR')
Returns the selected currency code. Defaults to the store's base currency.
swell.currency.selected() // => USD
In a multi-currency setup, format() will automatically consider selected currency options. Formatting with a display currency will cause a money value to be converted using a standard conversion rate which is updated daily.
swell.currency.format(10) // => $10.00
await swell.currency.select('EUR')
swell.currency.format(10) // => €8.874
See our help center for more details on multi-currency setup.