Hello Corvid Community ๐
I'm building a Ratings & Reviews app right now, there's two scenarios where I need to set different filters depending on the scenario, if the user is logged in and had already written a review I want to filter the dataset as usual but to show the user review on top of the list so he can see and edit it anytime he want, the second scenario is if the user is not logged in or didn't write a review yet.
export async function readReviews_ready() {
product = await $w('#productPage').getProduct();
let userId = wixUsers.currentUser.id;
let itemPurchased = await isItemPurchased(userId, product._id);
if (wixUsers.currentUser.loggedIn === true && itemPurchased === true
) {
$w('#readReviews').setFilter(wixData.filter()
.eq("productId", product._id)
.eq("approved", true)
.startsWith("_owner", userId)
)
.catch((error) => {
console.warn("readReviews Dataset Filter Failed")
});
} else {
$w('#readReviews').setFilter(wixData.filter()
.eq("productId", product._id)
.eq("approved", true)
)
.catch((error) => {
console.warn("readReviews Dataset Filter Failed")
});
}
}
On the first scenario, everything is working as expected, but on the second scenario where the user is not logged in I get two errors, one of them is yellow and the other is red:
Error 1: console.js:35 Failed to load initial data.
Error 2: readReviews Dataset Filter Failed.
The second error means the the filter couldn't be set on the dataset for some reasons, I don't why though! ๐ I also have a 403 forbidden error, but it's a an issue for another day.
Open the editor from here and go to line 95 to reach the above code.
As a logged in user who purchase an item, please use this product, I've placed an order before for testing. For non logged in users, you can use any product and open the developer tools (Cltr + Shift + I).
Note: When visiting other products, you need to refresh the page to grab the related result. I wish the Product Page element has an onChange event handler to handle the case where the product ID is changed.
Thanks a lot.
Hello.
You query fails because Reviews collection references the Members/PrivateMembersData collection.
Please note that this collection can only be read by logged in members. Therefore, only logged in members can read/query data from a collection referencing this collection.
Regards.