Adding Separate Ratings and Reviews to Dynamic Item Pages

I am completely new to Wix and Velo. I do not know any coding at all, but I was told the only way to add what I want to my website was to use code (the Editor and third party apps do not work for what I want).
Using the Wix Editor, I created dynamic list pages that lists multiple activities from an Activities Collection and dynamic items pages that shows detailed information for each activity.

This is the screenshot of the Activities Collection:


The Activity Title field is the primary field with the field key “title”.

This is the dynamic category list page that lists the activities by Module (i.e. Module 1, Module 2 etc. values shown in the Module field) for each activity.

This is the dynamic item page that shows the detailed content for each activity (like Activity Title, Activity Short Description etc).

On each activity’s page, under all the information, I want to add the option for users to add and view ratings and reviews for each activity on each activity dynamic item page, so that each page for each activity shows only the ratings and reviews submitted for that activity on that page and not show all the reviews submitted for all the activities on every activity page.

I found an old forum post https://www.wix.com/velo/forum/coding-with-velo/comments-reviews-on-dynamic-pages
If you scroll down on this page, there is a reply by Franz Coester on Sep 16, 2019 that includes some code on how to add ratings and reviews on dynamic pages.

Since I don’t really know much about coding, I don’t know how to edit this code to change the ids to refer to the items on my page, or the fields in my collections or anything…

I tried creating a Ratings collection like he says with a Reference back to my Activities collection (in his case his harbors collection/table), by adding a field in the collection, selecting the Field Type as Reference and selecting Activities collection under Referenced collection (please see screenshots below - the reference field is circled in red)

But I don’t know if I am doing this correctly or not, because in the screenshots from Franz Coester in the old forum post, the reference field is showing a database icon, while my reference field is showing some kind of link icon:

Frank Coester’s rating’s collection with reference field

My Ratings collection reference field:

This is part of the code he used load the rating to display the average and total number of ratings on the dynamic item page for each harbor:

$w.onReady( function () {
$w(‘#harbouritem’).onReady(() => {
harbouritem = $w(‘#harbouritem’).getCurrentItem()
loadrating()
})
});
exportfunction loadrating() {
let ratings;
wixData.query(‘Ratings’)
.eq(‘harbours’,harbouritem._id)
.find()
.then(result => {
ratings = result.items
let sumrating = 0
let countrating = 0
let rating = 0
countrating = result.totalCount
result.items.forEach(res => {
sumrating += res.rating
})
if (sumrating,countrating) {rating = sumrating/countrating}
$w(‘#harbourrating’).numRatings = countrating
if (rating > 0) {
$w(‘#harbourrating’).rating = rating
}
else {
$w(‘#harbourrating’).rating = undefined
}
})
}

I am having trouble understanding all the different things he is referring to in his code, like I don’t know what ‘#harbouritem’, ‘Ratings’,‘harbours’, harbouritem._id, ‘#harbourrating’ mean - are they the ids for elements on the page, the names of collections, fields from his collections or something else???

I also don’t know how to refer to a field in my collections in the code - like what the syntax is…

The # symbol seems to only work to refer to the ids of elements on the actual page, not a field in a collection.

Because I am not understanding what he is referring to in his code, I also don’t know what ids or code to substitute in his code so the code works with my collections, page elements etc.

So, I just need help from someone who can explain what each part of the code means and what I need to substitute to make it work for my website’s pages.

I greatly appreciate any help.

Thank you so much,
RT

Dear @thomasrt73

Thank you for posting this.
For 2 weeks now I am also looking to add reviews/comments to my test dynamic page and dynamic list.

There is an old Wix product page example from 2018 that was adapted by WixIdeas

He adapts the product page reviews to dynamic page reviews. I followed this example and it has worked on my test page.

My hurdle is adding the average review and % recommended to each repeater container in the dynamic list.
There is hardly any examples of doing this. (Wix should really do this).

I found the link to these examples by Wix

https://www.wix.com/velo/examples?search=rating

Which I hope will help you. (not for me so far).

I have also asked for help here - no replies yet.

Wix have these as examples for review elements, but it seems how the average is calculated is different in the example done by WixIdeas.

I don’t understand why Wix introduce a standard module for reviews and comments which can be added to the website like they have for Restaurant bookings etc.
It would really go a long way for people like us who use Wix for it ease of use features.
Adding comments/reviews has been a nightmare.

Hi @sammy

Thank you so much for replying to my post.

I finally figured out somewhat of a solution to this (except getting the percentage part - which I didn’t need and don’t know how to do).

I posted the solution on the forum:
SOLUTION: Adding Separate Ratings and Reviews to Individual Dynamic Pages

I am a complete beginner and don’t know coding, so please forgive any mistakes.

I hope this helps for what you are trying to do :slight_smile:

@thomasrt73

Thank you. I have just gone through your post.! amazing stuff.