Review system for dynamic pages using Velo code

Question:
[Need very brief help with some code. It’s for a custom Review functionality]

Product:
[Wix Studio Editor.]

What are you trying to achieve:
[I want to add a Review functionality like Store Products, but for Property listings as provided in dynamic page presets. Users must be able to add reviews under each listing item where they’ll be displayed.
The YT tutorial below is the closest thing to my requirement and I’ve been able to almost completely replicate it, with substitutions for my use case. Only thing I couldn’t solve is; connecting the Review to the the Property listing (dynamic item).
In Reviews CMS, all other fields are populated (Rating, Content, MemberReference). Only the Collection Reference is blank.
Seems to me the problem may be in the following line;
wixData.insertReference(“Reviews”, “property”, newReviewItem._id, property._id)

I’ve copied my code below, & screenshots]

What have you already tried:
[‘How To Create a Custom Product Review System for Your Wix Store | Wix Code - Velo’ (https://www.youtube.com/watch?v=OuXiT4Rccvo&t=1559s)
by ‘The Wix Wiz’

Relevant main IDs:
Dynamic Collection ID: Properties
MultiRef Field ID under Reviews Collection (that references above collection): property

My Code:
For Review Form Popup-

import wixData from ‘wix-data’;
import { currentMember } from ‘wix-members’
import wixWindow from ‘wix-window’;

$w.onReady(function () {
const property = wixWindow.lightbox.getContext();
console.log(“Properties”, property);
let member;

const checkForMember = async () => {
    member = await currentMember.getMember();
    if (!member) {
        $w("#SubmitReviewButton").disable();
    }
}

checkForMember();

const submitReview = async () => {
    const newReview = {
        content: $w("#contentInput").value,
        rating: $w("#ratingsInput").value,
    }

    const newReviewItem = await wixData.insert("Reviews", newReview);
    if (newReviewItem) {
        wixData.insertReference("Reviews", "member", newReviewItem._id, member._id)
        wixData.insertReference("Reviews", "property", newReviewItem._id, property._id)
    }
}

$w("#SubmitReviewButton").onClick(submitReview)

});

For Property Item Page-

import wixWindow from ‘wix-window’;

$w.onReady(function () {

$w(“#addReviewButton”).onClick(async ()=>{
const property = await $w(“#dynamicDataset”).getCurrentItem();
wixWindow.openLightbox(“Review Popup”, property);
})

});

]

Additional information:
[This Velo tutorial addresses my requirement, but doesn’t have enough steps for a non coder like me. (Ideas for Working with Your Wix Bookings App Collections)
Velo phrases for reference- (Dynamic Dataset is under ‘API reference’ > ‘wix-dataset’)

]

@thewixwiz - I see this is from your tutorial :slight_smile: - any insights?

2 Likes

Hi,

I don’t see anything fundamentally wrong as the insert member is working.
A few things I would add/check:

  1. insertReference is also a promise so I would add ‘await’ beforehand.

  2. I would wrap all promises in a try catch block to catch the errors.
    ex:
    try{
    await wixData.insertReference etc.
    }catch(error){
    console.log(error)
    }

  3. I would add a log right before the insert to log the value of property.

  4. Double check the field ID of property.

If you can share a link to a live site with this implemented that would help.

Eitan

1 Like

Dear Eitan,
Thank you for the response! I’m a fan of your channel.

1 & 2. I tried your code in 2 (albeit as a non coder. Screenshot of how I did attached below)
3. I don’t understand this
4. Checked. Same.

This is the link to my live site; a specific page of concern. https://www.vegananimalrights.com/properties/mid-century-styled-house
How I inserted your code

This is a core feature to my site, without which the site’s bottlenecked for weeks. You’d be solving a great burden if you can help me with this!

Gideon

1 Like

Hi Gideon,

Thanks for supporting the channel!

Upon testing I see this error in the console:

I would double check the update permissions on the properties collection and make sure members can update it (adding a reference in a multi reference field counts as an update action on a collection).

If you don’t want to allow member access to the collection you will need to handle the reference insertion as a backend function with auth suppressed. An alternative could be to just use a text field with the property ID as a reference but this may create blockers if you have a no code setup which depends on the reference.

Hope that helps.

Eitan

1 Like

Or you could try out a simpler tutorial …. it’s a bit of an oldie ……

1 Like

I can’t express enough how delighted I am. You nailed it YOU LEGEND! Yes, the problem was the permissions. This issue had me stuck and frustrated for weeks and thanks to you, it’s solved. Thank you so much Eitan!

3 Likes

Glad to hear, my pleasure!