convert external product price in other currency

Shopify Partner
6 0 0

I have an app that display products from a db that is not Shopify.

It displays a list of those products and show those products price in different currencies.


When a customer select a product from that list,

that product is added in the shopify store db through api.

And then the product is available for checkout.


My issue is to display the correct prices of my products in different currency before 

they actually exist in the shopify store db.

I am using this to get Shopify currency rates:

I am using this to calculate prices in different currency: 
getExchangePrice(amount, rates, from, to) {return (amount * rates[from]) / rates[to]}

The results I get in different currencies are always a little bit different than the one Shopify calculates when the product is being added in the store and giving all the presentment prices.

So I guess there is something I'm doing wrong.
I was thinking maybe I need to add on top of it that 1.5% to the converted price.
But still not quite getting same results, before and after the products gets added in Shopify store.


Here is some code as an example:
var p = 1099, c = Currency.convert(p,'USD','GBP'), f = 1.5 * c / 100;
console.log(`Currency(GBP):`, Math.round(c+f)); // should give the correct price I guess?

But no I get a price that is different than when I test in here:
admin/settings/payments/shopify-payments in the `enable currencies` section

Some help would reallyreallyreally be apreciated.
Thanks in advance


Shopify Expert
10275 144 1945

I don't think you should assume that the currencies JS file - and the data used for the multi-currency feature is the same.

You've got me very interested on why you need to do things that way. Are you able to explain or give a little more context on why?

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.

★ ★
Shopify Partner
6 0 0

Thanks for replying. Context is I have this app.
The app let a customer purchase products that are pulled from a different db than Shopify.
When a customer select those products, the app run a script in the backend that creates that new selected product in Shopify Store db before adding it to cart.

So until user add to cart, product price is not pulled from Shopify and doesn't have presentment price. Only price in usd.
I have a script to update those products and create presentment-prices imitating how Shopify does it.
But it's not working great. I've tried to find a work around but no luck.
script looks like this:

getExchangePrice(amount, rates, from, to) {
  return (amount * rates[from]) / rates[to];


const presentment_prices = v => {
    const raw_amount = this.getExchangePrice(price(v), exr.rates, `USD`, e);
    return {
      currency_code: e,
      amount: Math.round(raw_amount),

And I get rates from this:

15 2 2

Having the same issue, for example for 888$ USD to HKD I get:

$6882 - currencies.js

$6987 - checkout 


I would love to know if you were able to get this to work properly or not.