How to get consistent exchange rates that work with Hydrogen

As Shopify app developers, we aim to create applications that provide a consistent interface for both Liquid-based stores and Hydrogen-based storefronts. However, we face significant issues when it comes to handling currency conversion:

Currency Conversion in Liquid

  • In Liquid themes, Shopify.currency.rate is available for use in JavaScript. This is implicitly provided by Shopify through {{ content_for_header }}.
  • While this is not ideal (as it is only accessible on the client side), it allows us to convert simple numerical values, such as custom prices stored in metafields, into the store’s display currency.
  • This enables us to align the currency display of custom prices defined by the app (such as bundle discounts or option prices) with the currency display of standard products when “local currency display” is enabled.

Issues in Hydrogen

  • In Hydrogen, there is no equivalent to Shopify.currency.rate.
  • As a result, developers are forced to use external APIs or implement custom solutions. This approach may lead to discrepancies between the currency display of custom prices and that of regular products when using @inContext for currency conversion.

Why This Matters

  • Due to strict limitations in Shopify Functions, we as app developers often want to store store owners’ configured values as JSON-type metafields. Specifically, in this context, we frequently incorporate these values as “simple numbers” within a JSON structure rather than as “money type” values.

What We Are Looking For

We believe that if we could access exchange rates that shopify is using through the GraphQL Storefront API, this issue could be resolved.

Importance of a Solution

Without such a solution, building apps that function similarly across both platforms becomes unnecessarily complex and prone to inconsistencies. If Hydrogen could also access Shopify’s exchange rates, it would greatly enhance the consistency and efficiency of app development across platforms.

Thank you for the request, I’ll take the idea back to the team and see if we can add this to the backlog.

Ideally, you shouldn’t be using JavaScript to calculate your final price after currency conversion. Like you say, currency exchange rate are changing daily and we shouldn’t have discrepancies between displayed price and the prices show up in checkout.

A different approach to this is using MetaObjects. For example, you have a MetaObject with data type Money

Then create an entry under that MetaObject description with an amount. This is usually set to your shop base currency.

Use SFAPI query for that MetaObject. If you add inContext for a supported country currency that your shop has, it will return the Money amount in the currency that you specified in the inContext.

1 Like