Hello,
I created a reviews section on the product page that works great. However I want to use that same averaged number from the product page on the shop page like this;
I created a dynamic page with a repeater and a dataset tied to it.
Notice the review stars with total number of reviews. This is what I am trying to populate.
Here is the code from the product page;
async function loadStatistics() {
// Get the statistics data based on the current product's ID.
const stats = await wixData.get('review-stats', product._id);
// 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 percentRecommended = Math.round(stats.recommended / stats.count * 100);
// Get the ratings element.
let ratings = $w('#generalRatings');
let ratings2 = $w('#ratingsDisplay1');
// Set the ratings element's average rating to the value calculated above.
ratings.rating = avgRating;
ratings2.rating = avgRating;
wixData.insert("reviews", {"reviewAvg": avgRating});
// Set the ratings element's number of ratings to the count value from the statistics data.
ratings.numRatings = stats.count;
ratings2.numRatings = stats.count;
wixData.insert("reviews", {"numberofReviews": stats.count});
// Set the text for the recommended percentage element.
$w('#recoPercent').text = `${percentRecommended} % would recommend`;
// Show the ratings element.
$w('#generalRatings').show();
$w('#ratingsDisplay1').show();
// If there is no statistics data for the product:
} else {
// Set the text for the recommended percentage element to reflect the fact that there are no reviews.
$w('#recoPercent').text = 'There are no reviews yet';
}
// Show the recommended percentage element only after it is populated to avoid flickering.
$w('#recoPercent').show();
I added 2 lines highlighted above that writes the value of the average rating and number of ratings to my reviews collection so that I can use the data on the shop page with a dataset. What is happening is it is not showing up on the same line it creates a new line for the data.
See below; I highlighted where I want the data to write to.
I highlighted where I want these to be but instead they each get their own new line in the database collection. How can I make sure they end up on the same line.
Next how do I link this to the shop pages review stars for each individual product so it references the correct product only.
Thanks in advance.