How can I get shopping cart total on cart update for multiple currencies?

Highlighted
Tourist
6 0 0
Hello,
we run a shop with two currencies (CAD and USD) The default currency is CAD. With each update of the shopping cart a custom javascript function should be executed. For this purpose I have added a script block in theme.liquid.
jQuery( document ).ajaxComplete(function( event, xhr, settings ) {
   if ( settings.url == "/cart/update.js" || settings.url == "/cart.js") {
      var myObj = JSON.parse(xhr.responseText);
      console.log(myObj);
      …..
For further calculation I need the cart total (myObj.original_total_price).
Depending on the currency set in the shop, this should result in a different value. Example: three products each 25 CAD = 75 CAD. If the shop is switched to USD, the total should be USD 55.51.
 
Unfortunately myObj.original_total_price is always 75, which means that the cart object always seems to work with the default currency CAD. What can I do?
0 Likes
Highlighted
Excursionist
21 3 7

Sounds like all you have to do now is to add an if statement to your output to run a conversion depending on the selected currency.

I make custom Shopify pages & themes.. info@rgeekdigital.com
1 Like
Highlighted
Tourist
6 0 0

you're right. Unfortunately I don't know where to get the conversion rate. The currency object only returns "rate_updated_at" and "currency", but not the rate itself.

0 Likes
Highlighted
Excursionist
21 3 7

Understandable. In the absence of a rate, you have two options:

 

  1. Choose your figure (something like 75CAD would be  (75 x .75)USD)
  2. Or use a currency converter api (https://free.currencyconverterapi.com/).

 

Refer to this Stackoverflow page (https://stackoverflow.com/questions/41600987/currency-converter-in-javascript) for details on both options..

I make custom Shopify pages & themes.. info@rgeekdigital.com
1 Like