I’m building a loyalty app that uses the Ajax Cart API (/cart.js) from a theme app extension to simulate how many points a customer can earn on their current cart.
From /cart.js I’m reading values like:
json
Copy
{
“total_price”: 2925,
“total_discount”: 474,
“items”: [
{
“final_line_price”: 900,
“price”: 900,
// ...
}
],
“currency”: “INR” // or EUR, JPY, etc.
}
Questions:
-
Data format: Can you confirm that
total_price,total_discount,price,final_line_price, etc. are always returned as integers in the smallest currency unit (minor units), regardless of the currency (INR, EUR, JPY, etc.)? -
Decimals per currency: Is there an official way (or documented list) to know how many decimal places each currency uses (e.g. INR/EUR = 2, JPY = 0, KWD = 3), so that we can correctly convert from minor units to major units in a multi‑currency app? Or should we maintain our own ISO 4217 decimals table?
-
Exact amounts as shown in UI: Is there any Ajax API field or helper that returns the major‑unit amount (e.g.
29.25) or already formatted money value (same as what{{ cart.total_price | money }}shows in Liquid)?
Or is the recommended approach to:-
Use
total_price(minor units) +currency, -
And handle the division/formatting ourselves (e.g. using
10^decimalsandIntl.NumberFormat)?
-
Right now we’re doing total_price / 100 to get a decimal amount for our external loyalty API, but we realized this hard‑codes “2 decimal places” and might be wrong for currencies like JPY or KWD. We’d like to follow Shopify’s recommended / supported way for multi‑currency apps.