Am I Crazy For Wanting A Money Input?

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.

1 Like

yeah, that could be great. there are a lot of use cases. I had posted for it a while ago. but i don’t know what’s stopping them from adding.

however there is way around like having a random product with money metafield, then get the amount from that product metafield in theme coding.

I think the trick here would be that it would need to use exchange rates which are changing and also depending on the business they could agree specific rates which are more stable than market rates.

I think thats why for Shopify Markets you can see they let you set either the specific price in a currency or a exchange percentage.
There are then the contextual pricing in markets which does what you want but for product prices Contextual pricing for products is now available in the GraphQL Admin API — Shopify developer changelog

I imagine getting a field in a specific market will come when they roll it out more widely (I’m guessing).
An option in the interem, until something better is avaliable, is register translation of the metafield and get that depending on the country code.
Heres an example of how to do it in storefront api, but you can do it in liquid too Storefront API reference

So, for products we are fine. The clients tend to use Global E for their market manager so contextual layouts and market metafields don’t seem to really work or are just not accessible when using Global E.

I can see now that the currency conversion I am seeing when changing markets is because of the pricing map set up, not just from liquid knowing the original market price and apply a conversion when using the money filters.

That said, my gripe here is not for products, as I have 0 issues at all with product price issues. I am trying to figure out a reasonable solution to handle “custom” price elements. This is where I may offer a client a simple number input where they input the cents value of something like a free shipping threshold such as 50000 and when the cart is in USD, it’s all fine “Spend $500 For Free Shipping!”, but my cart is now in Yen, and I will see $500. So I convert that to using some money filters, but that just gives me “Spend ¥500 For Free Shipping” which is incredibly now. I need to figure out a clean system for establishing a base price and then converting that to the cart currency at the exchange rate. I am looking to somehow get “Spend ¥76850 For Free Shipping” when the cart currency / market is JPN.

I could establish a market metafielcd for “Free Shipping Threshold” and see if that can work, I just don’t know if I will have proper access to it when Global E is the market manager.

I know the old Shopify.formatMoney but that won’t do what I need. I see recently some people post about some Currency.convert JS function which seems to take in value and the currencies to convert, maybe that might work and I’ll settle for a JS solution I guess.