Skip to content
Cartly Developers

Multi-Currency Storefronts

Show prices in any currency. Automatic live exchange rates from OpenExchangeRates, per-currency markup, configurable rounding, and a Liquid fx_context for theme authors.

Overview

Multi-Currency lets your storefront visitors see prices in their preferred currency. Cartly fetches live rates from OpenExchangeRates every 6 hours via a Temporal cron workflow and stores them per shop. Each active currency can be configured independently with a mode (auto or manual), a markup percentage (0–25%), and a rounding strategy.

Key components:

  • Backend: internal/fxrates — provider, cron, ApplySnapshot, rounding pipeline
  • Pricing merge: internal/markets/pricing.go — per-rate inherit/override resolution
  • Liquid context: shop.fx_context — per-page bundle injected into every Liquid render
  • Storefront JS: boilerplate/assets/fx-converter.js

Admin API

Manage currencies via the /admin/currencies endpoints:

  • GET /admin/currencies — list all configured currencies with rates and stale flags
  • PUT /admin/currencies/:code — upsert a currency configuration
  • DELETE /admin/currencies/:code — remove a non-base currency
  • POST /admin/currencies/refresh — force-refresh all auto-mode rates
bashList currencies
curl https://cartly.pro/admin/currencies \
  -H "Authorization: Bearer $ADMIN_TOKEN"
# Response: [{ "code": "EUR", "mode": "auto", "rate": 0.92, "markup_pct": 2, "rounding_strategy": "nearest_99", "stale": false }, ...]
bashAdd / update a currency
curl -X PUT https://cartly.pro/admin/currencies/EUR \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "auto",
    "markup_pct": 2.5,
    "rounding_strategy": "nearest_99",
    "active": true
  }'
# rounding_strategy: "none" | "nearest_99" | "nearest_95" | "nearest_whole"
# mode: "auto" (OpenExchangeRates feed) | "manual" (merchant-entered rate)
bashForce rate refresh
curl -X POST https://cartly.pro/admin/currencies/refresh \
  -H "Authorization: Bearer $ADMIN_TOKEN"
# Force-refreshes all auto-mode rates. Rate-limited to 5 req/min/IP.

Liquid fx_context

Every Liquid render receives shop.fx_context — a per-page bundle containing the visitor's display currency, all supported currencies with their rates/markup/rounding, and a stale flag (true when the most recent rate is older than 24 h).

liquidLiquid fx_context usage
{# Liquid — access fx_context from the request global #}
{% assign fx = shop.fx_context %}
{% assign display_currency = fx.display_currency %}
{% assign rate = fx.rates[display_currency] %}
{% assign stale = fx.stale %}

{# Render the currency picker #}
<select id="currency-picker" data-fx-display-currency="{{ display_currency | escape }}">
  {% for entry in fx.supported_currencies %}
    <option value="{{ entry.code | escape }}"
      data-rate="{{ entry.rate }}"
      data-markup="{{ entry.markup_pct }}"
      data-rounding="{{ entry.rounding_strategy }}"
      {% if entry.code == display_currency %}selected{% endif %}>
      {{ entry.code }}
    </option>
  {% endfor %}
</select>

{% if stale %}
  <p class="fx-stale-warning">Exchange rates were last updated over 24 hours ago.</p>
{% endif %}

Important: data inside {% render %} snippets is isolated from the parent template's scope. The fx_context is available as an engine global (set via engine.globals in the Go Liquid renderer), so it is accessible everywhere — including inside {% render %}tags — without needing to pass it explicitly.

Storefront JS

boilerplate/assets/fx-converter.js exposes window.cartlyFXfor client-side currency conversion. Use it when building interactive currency pickers or live price updates without a page reload.

typescriptwindow.cartlyFX API
// boilerplate/assets/fx-converter.js is loaded on every storefront page
// (content_for_header); it reads the page's FX bundle (#cartly-fx), so the
// rate, markup and rounding are the ones the server rendered the page with.

// Convert a shop-base-currency price (minor units) to a display currency.
// Returns minor units of the target currency, or null without a rate.
const eurCents = window.cartlyFX.convertCents(1999, "EUR"); // e.g. 1899

// Format like the Liquid | money filter, in the page's display currency
const label = window.cartlyFX.formatMoney(1999); // e.g. "€18.99"

// Format an amount already in a currency (no conversion)
window.cartlyFX.formatIn(1899, "EUR"); // "€18.99"

Cartly uses the cartly_currency cookie to persist the visitor's currency choice across pages and sessions. The cookie is set to Secure; SameSite=Laxon HTTPS storefronts.

liquidReading the active currency
// The storefront sets cartly_currency=EUR via a form POST to /?currency=EUR
// The cookie is Secure; SameSite=Lax on HTTPS storefronts.
// Reading the active currency in a Liquid template:
{% assign display_currency = shop.fx_context.display_currency %}
<p>Prices shown in: {{ display_currency }}</p>

ISO 4217 validation is enforced on the cookie value — invalid codes are silently ignored and the shop base currency is used as fallback.

Rounding Strategies

Rounding is applied after the rate conversion and markup. Each currency row can override the shop-level default rounding, or explicitly set"none" to suppress rounding even when the shop default is active.

  • none — raw converted amount, no rounding
  • nearest_99 — round to nearest .99 (e.g., €18.40 → €17.99)
  • nearest_95 — round to nearest .95
  • nearest_whole — round to nearest whole unit (e.g., €18.40 → €18)

The inherit-vs-override distinction is important: a per-currency row with rounding_strategy: "none" is respected even when the shop default is "nearest_99".

Zero-Decimal Currencies

BIF, CLP, DJF, GNF, HUF, ISK, JPY, KMF, KRW, PYG, RWF, UGX, VND, VUV, XAF, XOF, and XPF are zero-decimal currencies — their prices are integers and must not be rounded to a .99 suffix. Cartly skips the cents-math rounding step for these currencies automatically. A ¥3,714 price stays ¥3,714, never inflating to ¥3,799.

See also: Set up automatic exchange rates (Help Center)