I’ve followed the guide here for adding review and ratings for products (im using for items) and the code is working for the reviews and they are automatically updated.
The guide i’ve followed is here: https://www.wix.com/code/home/example/Shop-Reviews
But the review statistics (average ratings is meant to be automatically updated too) isn’t working. I’ve changed the id where needed and changed the sumand numratings to align with my field keys. Not sure what’s going wrong. This is my code:
async function updateStatistics(isRecommended) {
let stats = await wixData.get(‘Review-stats’, projectName);
if (stats) {
stats.sum += parseInt($w(‘#radioRating’).value, 10);
stats.numRatings += 1;
return wixData.update(‘Review-stats’, stats)
}
stats = {
_id: projectName,
sum: parseInt($w(‘#radioRating’).value, 10),
numRatings: 1,
};
return wixData.insert(‘Review-stats’, stats)
}