Coding errors - Getdata count and Setfilter

Full disclosure - this is the first time I have attempted code like this and I am VERY much learning as I go. I have followed a Corvid tutorial (for the past 8 hours!) and now have reduced errors to two, which I cannot work out. Any help would be greatly appreciated - would be fab to have achieved something in lockdown :joy:

I am trying to add a product review function and have followed this to a T (or so I thought): https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site

I have two errors attached and am out of my depth…

Thanks in advance :woman_facepalming::blush:

Hello Joanna,

if you would use the CODE-TAGs to insert the code as TEXT and not as IMAGE, i could perhaps take a look at this issue. I do not want to type/write all this code by my own to reconstruct your situation :grin: I am a lazy man.

But i can already recognize some errors in your code.

if ('#review').getTotalCount() > 0) {   <<<<---- WRONG

Look at this… (you have forget —> $w(…

export function showReviews() {
 if ($w('#review').getTotalCount() > 0) {
  $w('#reviewsStrip').expand();
 } else {
  $w('#reviewsStrip').collapse();
 }
}

Second one… (do not recognize the error but try this one)

async function initReviews() {
 await $w('#productPage1').setFilter(wixData.filter().eq('productId', product._id));
 showReviews();
 loadStatistics();
}

Thank you for such a great reply! Code is not flagging any errors now - hooray! Final issue is that the code isn’t loading reviews on product pages. Can you spot any similar errors in the code here? I’m not sure how the code understands if there is more than one review (for the get total count), I have included a screen-grab of the database too. Thanks again!!

@joannamcgowanmusic

do you have implement the ā€œloading-partā€ to your code?

loadStatistics() //<--- this wants to start the loading process

Where is your loading part?
Do you have this part in your CODE ?

async function loadStatistics() {
 const stats = await wixData.get('review-stats', product._id); 
 if (stats) { 
 let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); 
 let percentRecommended = Math.round(stats.recommended / stats.count * 100); 
 let ratings = $w('#generalRatings');
  ratings.rating = avgRating;
  ratings.numRatings = stats.count;
  $w('#recoPercent').text = `${percentRecommended} % would recommend`; 
  $w('#generalRatings').show(); 
 } else {
  $w('#recoPercent').text = 'There are no reviews yet'; 
 }
 $w('#recoPercent').show(); 
}

Of course you have to optimize it and to modify for your own project.

Try do read the tutorial, one more time and to understand all the steps.
STEP by STEP!

@russian-dima Thank you for your reply - the issue for me with the tutorial, is that they have already set up databases/site content prior to the instructions. I went on the example site (on wix editor) and copied content so all tags are the same, but I wouldn’t know if I have made an error on that side of things.