I have a review system for wix store that works great on the product page,would like to display the total number of reviews and the aggregate of the stars in a star rating display on a different page,i am trying to reuse the code that works great on the product page but not on a separate page,any guidance?Thank you
ERROR -> however the database fields are correct
Wix code SDK error: The rating parameter that is passed to the rating method cannot be set to the value NaN. It must be of type number. Line 20
Wix code SDK Warning: The numRatings parameter that is passed to the numRatings method cannot be set to null or undefined. Line 21
/*$w.onReady(function () {
/*$w('#dataset2').setFilter(wixData.filter('reviews')); //dataset with the reviews
loadStatistics();
// Load the current product's statistics. function loadStatistics() { const stats = wixData.get('review-stats'); //dataset with the statistic reviews for each product // If statistics data for the product was found: if (stats) { // Compute the product's average rating by dividing the total points by the number of ratings. let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); // Compute the percentage of reviewers that recommend the product. let ratings = $w('#generalRatings');//rating display // Set the ratings element's average rating to the value calculated above. ratings.rating = avgRating; //line20 // Set the ratings element's number of ratings to the count value from the statistics data. ratings.numRatings = stats.count; //line21 // Set the text for the recommended percentage element.
} } });
Line 20
NaN basically stands for not a number, you need to be using a number (has to be a whole number only) which the javascript in Wix code will recognise as an actual number.
https://www.w3schools.com/jsref/jsref_number_nan.asp
Line 21
Your code is not receiving a number in return when it looks for the numRatings value.
As for code itself, the Wix tutorial for ratings and reviews in Wix Stores is designed to be shown for each product on each product's own page and not elsewhere.
https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site
The same with the ratings and review tutorial for a normal Wix page, it is still only designed to be shown all on the same page.