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’)
]