Shopify / ui-extensions

MIT License
254 stars 35 forks source link

Make available exchange rate in checkout ui extensions API #613

Open catalin-invisible opened 1 year ago

catalin-invisible commented 1 year ago

Please list the related package(s)

checkout-ui-extensions

If this related to specific APIs or components, please list them here

https://shopify.dev/api/checkout-extensions/checkout/extension-points -> Shopify specific globals

Is your feature request related to a problem? Please describe.

When developing a checkout ui extension app, we do not have acces via the existing API to current currency exchange rate. For example, in regular Shopify stores, we have this info available by accessing window.Shopify.currency.rate, which describes the exchange rate between the store's primary market currency and the current store currency.

Currently, checkout UI extensions API provides currency information under localization.currency.current.isoCode, but no details about the exchange rate.

Describe the changes you are looking for

To have the exchange rate provided via API similarly with localization.currency.current.isoCode

dnagoda commented 1 year ago

Duplicate request: https://github.com/Shopify/ui-extensions/issues/1084

gil-- commented 1 year ago

I've love to see a reimplementation of what Shopify Functions provides:

presentmentCurrencyRate (decimal): The conversion rate between the shop's currency and the currency of the cart.

https://shopify.dev/docs/api/functions/reference/delivery-customization/graphql/input

This would enable quick multi-currency conversions within extensions without looking up or caching currency rates.

Adham-Mamedov commented 6 months ago

Is there still no implementation for exchange rates?

Briggzly commented 5 months ago

so still nothing? I feel this is a huge oversight.

catalin-invisible commented 2 months ago

I just came across another scenario where multiple currency exchange rates are needed in a Shopify headless integration using Storefront API.

An update on this would be great, thank you!

benjitastic commented 2 months ago

Also watching this. We have a store credit threshold in place (spend $100 USD) and if the cart currency is in EUR I have no way of checking in the checkout extension if the cart total/cost is above or below $100 USD.

FranciscoBejaranoBluEdgeUsa commented 2 months ago

We need this feature right now for one of our clients using Markets Pro!

How are we supposed to localize our UI extensions for clients selling outside the US?

Tw33t3r commented 2 months ago

This is blocking our company from properly adopting checkout extensions. We've made a workaround to add a Money typed metafield in one currency and rely on Shopify's automatic conversion at checkout time. This means we have to build a new metafield and handle it for each currency pair we want to support. It would be great to have a proper solution for this.

Kaniwong commented 1 month ago

Same need. We want to convert price infos based on our store's currency to the customer's currency. For example: 30% OFF OVER £150.00, we need to change this to the customer's currency to make it clearer

FranciscoBejaranoBluEdgeUsa commented 1 month ago

Hi Everyone, at Bluedge USA we solved this issue by using “money” metaobjects instead of metafields.

We create a metaobject definition with a single value type of "money", we create a single entry in this metaobject with a static handle and a value of "1".

Then inside our checkout UI extensions, we query the storefront API using the context directory with the current country iso_code set in the checkout to get the exact currency exchange rate.

Something like this:

    query @inContext(country: ${isoCode}) {
        metaobject(handle: { type: "currency", handle: "currency-rate" }) {
            id
            field(key: "rate_helper") {
                value
            }
        }
    }

For now, this is the best we would come up with, but a native, Shopify made solution is still 100% needed to avoid querying the storefront directly.

Please release this as soon as possible!

chienit3bk commented 3 weeks ago

Also watching this.

benjitastic commented 2 weeks ago

For anybody still trying to solve this here's how I did the workaround FranciscoBejaranoBluEdgeUsa mentioned above. Make a currency conversion meta object on the store with a conversion field with type of Money:

image image

Then create an entry for $100,000:

image

Then you can use that content entry in your extension like this:

  const { i18n, localization, query, lines } = useApi()
  const [currencyConversion, setCurrencyConversion] = useState()

  useEffect(() => {
    const country = localization?.country?.current?.isoCode || 'US'
    query(
      `query @inContext(country: ${country}) {
        metaobject(handle: {
          type: "currency",
          handle: "currency-conversion"
        }) {
          id
          handle
          field(key: "conversion") {
            value
          }
        }

      }
      `
    )
    .then(({ data, errors }) => {
      setCurrencyConversion(JSON.parse(data?.metaobject?.field?.value))
    })
    .catch(console.error);
  }, [query]);

To go from non-USD to USD:

const subtotalUSD = amount / (currencyConversion?.amount / 100000)

To go from USD to non-USD checkout currency:

i18n.formatCurrency(amount * currencyConversion?.amount / 100000, {
    currency: currencyConversion.currency_code,
})

I found that setting the conversion object to 100000 worked better than 1 when you start dealing with some very broad denomination differences between some currencies and 1 would not have enough precision.