Lately, I have been working on client themes with tasks related to money formatting. Some themes use an older style of a number input where a cents value is entered and we just pass that through some money filters. That works when the cart currency matches the shop currency, but when the cart currency changes, the result is really against intention.
What I am trying to change to, is try to transition any number
input away and try to source any financial value from a money
type field on a metaobject or standard resource and use money filters on that. I stay away from JS based money formatting functions, and instead I try to source from a snippet that holds a price map with money
filter results in JSON object. I’ll also add a product template, which just fetches that snippet result with the current product or variant. When the money value I want to convert is a formal money type, there really aren’t problems,
So when do I run into problems? I may have a hero or announcement bar where you can input a value in cents with a number input in a section. I enter 50000 for my threshold value. My shop is USD, so 50000 | money
is going to get me “$500”, my cart changes to Yen, and I get “¥500” which is not exactly a correct conversion. Which makes sense as my code is saying show me numerical value 50000 in “¥” not “Show me the equivalent of $500”. Let’s say I have a threshold I want to show “spend a for free shipping” “spend a for this gift with purchase” “you’re (a-b) away from earning a gift with purchase!”. A shop may have a hero or announcement bar where the client types in a financial threshold amount, and we really really want this to change as the currency does.
If I had a money
input, the client could just type in the value they want (based on the shop currency), then ideally as money
filters are used on this value, the initial numerical value would be converted to the current cart
currency. A hero section can say “Spend $500 For Free Shipping”, I change my currency to Yen and now I see “Spend ¥76,877.49 For Free Shipping”
This also reminds me, we love to do math and show the customer how much more they need to spent to hit the requirements. I have never tried this, but can you do money math in liquid? I know in Shopify Scripts it was a little weird…
For extra info, most clients I work with use Global-e, which adds a layer in difficulty.
So am I entirely crazy here? I want to use JS solutions as a final resort, I really have a larger love for server side results first.