Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Correct or set the cookie in jquery ajax request

I need to take data from this URL: https://e453eb.myshopify.com/products/chakananecklace.json

and I write a code:
// Now, make the AJAX request

    $.ajax({
        url: 'https://e453eb.myshopify.com/products/chakananecklace.json',
        type: 'GET',
        success: function(data) {
            // Handle success
console.log(data);
        },
        error: function(xhr, textStatus, errorThrown) {
            // Handle error
        }
    });

all is fine just I get data.variant[0].price in user’s local currency and not the default currency. How I can fix that? Can I send a header with user locale to get the correct results to can I set the user cookie[‘cart_currency’] to USD

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Also if not possible to set the desired currency, how I can get the response cookie [‘cart_currency’]

The problem is that I got prices but I don’t know which currency is that, because Shopify gives prices based on user locale

>Solution :

To ensure that you receive the prices in the default currency regardless of the user’s locale, you can try adding a currency parameter ( as a query param) to the URL when making the AJAX request. This parameter specifies the currency in which you want the prices to be returned. In this case, you want the prices in USD. Here’s how you can modify your code:

// Now, make the AJAX request
$.ajax({
    url: 'https://e453eb.myshopify.com/products/chakananecklace.json?currency=USD',
    type: 'GET',
    success: function(data) {
        // Handle success
        console.log(data);
    },
    error: function(xhr, textStatus, errorThrown) {
        // Handle error
    }
});

You can directly hit this URL in browser and play with currency.

https://e453eb.myshopify.com/products/chakananecklace.json?currency=USD
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading