Hello, everybody.
I have made rating system on existing wix booking site.
The site works well when I login with my admin account.
But when I visit the site and make a new account and login, then it troubles.
It shows the review and ratings of the service, but doesn’t show the reviewer’s name and image.
This is our site: tlxproservice.com
This is the databbase structure of our site:
Reviewer field in service_reviews collection is reference field connected to privatemembers collection marked above.
As you can see below, the Review repeater is linked with service_reviews data collection.
Reviewer’s name is linked with the reference field and the review is linked with Review(text) field.
The problem when I login with new account is as follows:
- The review’s data doesn’t appear on repeater
- I can’t make a review
Now no 1 is quite clear for you, I think. Let me explain more about no 2.
I got the current user’s data with following code:
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
$w(‘#GetReviewDataset’).onBeforeSave(() => {
let user = wixUsers.currentUser;
let current_service = $w(‘#BookingItemdynamicDataset’).getCurrentItem();
$w(‘#GetReviewDataset’).setFieldValue(‘service’, current_service._id);
$w(‘#GetReviewDataset’).setFieldValue(‘reviewer’, user.id);
})
$w(‘#GetReviewDataset’).onAfterSave(() => {
let current_service = $w(‘#ServiceInfo’).getCurrentItem();
let review_count, total_rating, new_rating;
review_count = current_service.reviewCount;
total_rating = current_service.totalRating;
new_rating = $w(‘#RatingInput’).value;
// update the review count and total rating
$w(‘#ServiceInfo’).setFieldValues({
‘reviewCount’: (review_count + 1),
‘totalRating’: (total_rating + new_rating)
})
$w(‘#ServiceInfo’).save()
.then((result) => {
console.log(‘updating…’)
$w(‘#ServiceInfo’).refresh();
calculateRating();
console.log(‘…updated’)
})
.catch((err) => {
console.log(‘error saving’);
});
$w(‘#ServiceReviewsDataset’).refresh();
});
$w(‘#ServiceInfo’).onReady(() => {
calculateRating();
});
});
I would like to listen to your opinion why there problems happen.
If you can’t understand what I mean, I will provide you more information.
Thank you in advance.