Hi, I’m trying to show the product prices in the local currency automatically. Here are the steps that we have implemented.
Step-1: Detecting the user’s country/currency using an api - This is working perfectly!
Step-2: Modifying product prices using conversion rates - This is also working perfectly!
Step-3: Lastly, displaying converted prices - We are not able to make this part work. Any suggestion would be highly appreciated. Thanks!
In the console.log, we see that the converted price is there, however, we are not able to display it on the page.
Screenshot 1:
Screenshot 2:
Code
// Function to update product prices based on the currency
function updatePrices(currency) {
const conversionRate = currencyConversionRates[currency];
console.log(currency)
$w('#currencyDD').value = currency;
// Update each product price based on the conversion rate
$w("#dataset1").onReady(() => {
$w("#dataset1").getItems(0, Infinity).then((result) => {
// console.log("result ", result)
result.items.forEach((product) => {
// console.log("product ", Products)
const discountedPrice = product.discountedPrice; // Original price in base currency (e.g., USD)
const convertedPrice = discountedPrice * conversionRate;
product.currency = currency;
product.discountedPrice = convertedPrice; // Update the product's price in the desired currency
console.log("upProd ", product)
$w('#dataset1').update(product);
});
})
})