k.commerce.currency
Currency management.
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure store currency and exchange rates in commerce settings | Display currency switchers, read default currency code, and convert prices |
k.commerce.currency provides currency list lookups and exchange-rate conversions.
Quick Start
js
k.api.get(() => {
const defaultCode = k.commerce.currency.default
const currencies = k.commerce.currency.list()
const converted = k.commerce.currency.convert("USD", "CNY", 2)
return { defaultCode, currencies, converted }
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
default | Store default currency code (e.g. "CNY") | string |
list() | List configured currencies and exchange rates | CurrencyItem[] |
convert(from, to, value) | Convert an amount between currencies (uses site manual rate only when from is default currency and to has auto-update disabled; otherwise queries remote rate service) | number |
default
Read-only property returning the store default currency code. No parameters.
Returns: string
js
k.api.get(() => {
return k.commerce.currency.default
})list()
Get a list of supported currencies. No parameters.
Returns: CurrencyItem[]
js
k.api.get(() => {
return k.commerce.currency.list()
})convert()
Convert an amount between two currency codes.
Rate Resolution & Exceptions
- Site manual rate: A store-configured manual
exchangeRateis used only whenfrommatches the store default currency (case-insensitive) andtois configured in the store withAutoUpdatedisabled. - Remote rate service: In all other cases (including conversions from a non-default currency, unconfigured target currencies, or currencies with
AutoUpdateenabled), Kooboo queries the remote Kooboo account server and caches rates locally for 3 days (exchangeRates.json, refreshed in the background after expiry). - Errors: Passing empty/whitespace currency codes or failing to fetch from the remote rate service throws an exception (when
fromequalsto, rate1is used directly).
| Parameter | Type | Required | Description |
|---|---|---|---|
from | string | Yes | Source currency code |
to | string | Yes | Target currency code |
value | number | Yes | Amount to convert |
Returns: number - Converted amount
js
k.api.get(() => {
const usdAmount = 2
const cnyAmount = k.commerce.currency.convert("USD", "CNY", usdAmount)
return { usdAmount, cnyAmount }
})Structure
CurrencyItem Property
| Property | Description | Type |
|---|---|---|
name | Currency name | string |
nameNative | Local currency name (mirrors English name for default currency; currently null for non-default currencies) | string | null |
code | Currency code | string |
symbol | Currency symbol | string |
exchangeRate | Exchange rate | number |
TypeScript Definitions
ts
interface KCurrency {
default: string;
list(): CurrencyItem[];
convert(from: string, to: string, value: number): number;
}
interface CurrencyItem {
name: string;
nameNative: string | null;
code: string;
symbol: string;
exchangeRate: number;
}Related Docs
- k.commerce - E-commerce module overview
- settings - E-commerce settings