I need to create a review for products but I'm having trouble getting the product and populate the database with the product and review information, and then load the database information on the product page. Could someone help me write this code?
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
i am trying to create a review for products but without wix stores , and using the wix code let product; $w.onReady(async function () { product = await $w('#productPage1').getProduct(); initReviews(); });
do not work, any help would be great, thank you
The next training will be how to create a new product page with wix store api. This will help the page load faster.
Yes,
The training was on July 4 and only today they sent me this YOAV link.
It's exactly what you wanted right?
You were smarter than me and probably follow the YOAV publications and received the same day of the training. Hope you got what you wanted on your site with this code!
Yoav just posted this. Saved us some time coding for the repeater!
https://www.wix.com/code/home/forum/wix-tips-and-updates/example-store-reviews-rating
Thanks for letting me know!
Next Wednesday there will be a webinar showing what we can do with the Wix Store API, maybe there will be some news about it over there
that sounds like something that will take a painful amount of time to do...
Hi,
I also found this solution, only the link that opens in another window that does not look cool, I thought of trying to work with openModal. Influencelly wix does not allow to work the html, css and javascript of complete way. They also do not offer the necessary examples of what we can do and it seems that the Wix team left the forum and now it is the responsibility of moderators.
Another solution would be to delete the renderReview code and create a new one using site elements for each object rating, review and image.
I use a temporary solution for adding images. Within the Renderreview function, I added the line below and added a url section in the Wix database. I manually convert the format to URL for now. I am trying to come up with a solution.
<a href="${(review.imageUrl)}"> <img src=${(review.imageUrl)} alt="" style="max-width:285px;max-height:285px;"> </a>
Hi, of course, I'll study a way I hope it works out and I'll get back to you.
Thanks for your reply. Do you think you can figure out a way to allow commenters to attach an image and have it shown on the comments section? I am able to enable commenters to attach an image, but have difficulty showing the images in the comments section as the comments section is rendered in html code, instead of Wix code.
Hey man, I came in here now to tell you what I got this time, and I saw the piece of code above. Thank you very much for your kindness! Even though I already have it, I'll save your code.
If you add the following code to your site only users can add reviews.
export function productPage1_viewportEnter(event, $w) {
if (user.loggedIn) { $w('#addReview').enable();
loadReviews(2); } else { $w('#addReview').label = "Only users can review"; $w('#addReview').disable(); }
Thank you. Its cool talking to you.
To save you some time,
Replace the following portion
import wixWindow from "wix-window";
import wixData from "wix-data"; export function addReview_onClick(event) { let recipeId = $w('#dynamicDataset').getCurrentItem()._id; wixWindow.openLightbox('Post a Review', {id: recipeId}); } export function dynamicDataset_onReady(event) { let recipe = $w('#dynamicDataset').getCurrentItem(); // setting the rating as HTML to have fine grained control over the formatting let foodistaLink = recipe.linkFromFoodista; $w('#foodistaCredit').html = `<p style="font-size:10px; line-height:1.2em; text-align:center"><span style="letter-spacing:0em"> <span style="font-size:10px"><span class="color_11"><span style="font-weight:bold"> Recipe originally published by <span style="font-family:avenir-lt-w01_85-heavy1475544,sans-serif"><a href="${foodistaLink}" target="_blank">Foodista.com</a></span></span></span></span></span></p>`; loadReviews(2); } function loadReviews(limit) { let recipe = $w('#dynamicDataset').getCurrentItem(); wixData.query('reviews') .eq('recipeId', recipe._id) .find() .then(res => { if (res.length > 0) { renderRating(res.items); renderReviews(res.items, limit); $w('#numberOfReviews').text = `${res.length} Reviews`; $w('#numberOfReviews').show(); if (res.length > 2) { $w('#seeAllReviews').show(); $w('#seeAllLine').show(); } } else { $w('#rating').hide(); $w('#numberOfReviews').text = 'No Reviews'; $w('#numberOfReviews').show(); } }); }
with this
import wixWindow from "wix-window";
export function seeAllReviews_click(event, $w) {
loadReviews();
}
export function productPage1_viewportEnter(event, $w) {
loadReviews(2);
}
export function addReview_onClick() {
let productId = product._id;
wixWindow.openLightbox('Comment', {
id: productId
});
}
function loadReviews(limit) {
wixData.refresh
wixData.query('reviews')
.eq('productId', product._id)
.find()
.then(res => {
if (res.length > 0) {
renderRating(res.items);
renderReviews(res.items, limit);
$w('#numberOfReviews').text = `${res.length} Reviews`;
$w('#numberOfReviews').show();
if (res.length > 2) {
$w('#seeAllReviews').show();
$w('#seeAllLine').show();
$w('#seeAllLine2').show();
}
} else {
$w('#rating').hide();
$w('#numberOfReviews').text = ‘No Reviews’;
$w('#numberOfReviews').show();
}
});
}
At first I also used this example but it did not work, I'll use your tip this time. Then I'll tell you how it went! Thanks.
https://www.wix.com/code/home/example/Reviews
I made one using this example provided by Wix Code.
Instead of getCurrentItem from a dataset, you use getProduct, and everything should be fine.