Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
I am making my little Shopify application and cannot understand how I can get the rounding rules for Shopify Plus store with multicurrency. There is Shopify.currency object in the JS console on the shop page, but rates, provided by this object don't take into the account rounding rules. How can I convert any product price to another currency?
Sample of my problem:
I have a 3.49 USD product in my cart: Shopify.currency #=> {rate: 1.0, active: 'USD'}
let's change the currency to CAD, for example {active: "CAD", rate: "1.35582685"}
Cart price will be 5.00 CAD, but
5.00 / 1.35582685 = 3.6877865340991 3.49 * 1.35582685 = 4.7318357065
Rates are very different from the amount in the cart.
Hey @lazynick.
At this time, we don't offer the specific conversion rate by any supported means. Unfortunately this means that you don't really have a way to get the exact conversion until we can offer a solution to this problem.
It's something we're seeing requested often, so it's definitely a pain point we're aware of.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
@Alex wrote:It's something we're seeing requested often, so it's definitely a pain point we're aware of.
Add me to that request,
Doing anything simplistic is further frustrated by the fact that:
Getting around this means hitting the shopify servers at least two times:
Then you can do your estimate+rounding.
Main story is these aspect not being exposed means the upgrade path of switching a theme over to using the new multicurrency and making it seemless is currently non-trivial.
When the merchant and customers are used to a smooth ajax switcher you pretty much have to rewrite new switcher code instead of being able to output multicurrency prices as hooks in the html and use what's already there.
Hi,
You could create a visually hidden product (call it "Currency Base") and give it a price of $10,000,000 in your shop currency.
Knowing that you gave it a price of $10,000,000 (1000000000 in liquid terms) you can divide that by the converted price Shopify outputs your theme to get the conversion rate:
{% assign baseRate = 1000000000 %}
{% assign convertedRate = all_products['currency-base'].price | times: 1.0 %} {{ baseRate | divided_by: convertedRate }}
Hope this helps!
Sebastian
This is an excellent solution for getting Shopify’s currency rate in your liquid templates! I've used a similar method before for getting the currency rate via the API for backend functionality, but it never occurred to me that the same trick would work via liquid.
One slight change I would suggest though, is to set your currency product to 100 million dollars rather than 10 million. The reason is that Shopify's currency rate goes to 8 decimal places, and using a value less than this causes your new rate to be rounded by one decimal place. Practically speaking this won't make a difference unless you're selling absurdly high-cost items, but pedantically speaking it's nice to have the rate be exact 😊. I've also confirmed that the rate you get by this method matches the Shopify.currency.rate Javascript object that is present on the Storefront.
Here is my updated version of your code to populate a variable with the currency rate:
{% assign currencyRate = all_products['currency-base'].price | divided_by: 10000000000.0 %}
And then to output the currency rate:
{{ currencyRate }}
or to calculate a price:
{% assign customPrice = 1599 %}
{{ customPrice | times: currencyRate | money_with_currency }}
*Notes:
@Ginko wrote:Hi,
You could create a visually hidden product (call it "Currency Base") and give it a price of $10,000,000 in your shop currency [...]
The JS object window.Shopify.currency.rate is showing the incorrect rate, and I don't see any way to get the real rate in the frontend.
A real world example:
window.Shopify.currency.rate is returning 0.86456832
Accordingly with this rate the price of a product that costs 99.99 should be 86.44
But the price in the product page is showing 86.95, which gives the rate 0.8695869586958697
As you can see, the rate of window.Shopify.currency.rate is totally wrong.
Middle of 2021 and no solution for this yet?
Hi,
Any update on this?
User | RANK |
---|---|
6 | |
5 | |
4 | |
3 | |
3 |