Hello guys,
First of all THANKS FOR Wix to provide example code of Wishlist feature for Store ! Here is the reference.
My problems is that since I would like to set up the wishlist feature for my own Database Collection and repeater instead of using Store Module as the example has, some function and code structure in the example wont be applicable anymore (i.e. getProduct()).
Anyone may have guidance of how possibly I can modify the example code to fit in my need? More details would be so much appreciated!!!
Thanks in advance and look forward advices from this community 
Thanks,
Will
1 Like
Hey
sure but first describe your scenario so I can think about How to use wishlist Sample in your Case.
I have the same situation I operated the page where the products appear, but I do not operate the wish list page I can not work correctly the repeater that shows the favorite elements because although it shows the number of elements that I have as favorites the repeater does not bring the image the product name or category
@abigailx1
Instead of using code like getProduct() try using wixData.query()
If you need help create a new thread in the forum.
@wixcodeextracts I’m going to create it because I couldn’t make it work completely, my problem is in the page that shows the wish list.
This works for me in the product section, with out store taking the info from database, i change:
// Get the currently displayed product. product = await $w(“#dynamicDataset”).getCurrentItem().nombre_emp;
where “nombre_emp” is the name of product.
//-------------Imports-------------//
// Import the wix-data module for working with queries.
import wixData from 'wix-data';
// Import the wix-users module for working with users.
import wixUsers from 'wix-users';
//-------------Global Variables-------------//
// Current product.
let product;
// Current user.
let user = wixUsers.currentUser;
//-------------Page Setup-------------//
$w.onReady(async function () {
// Get the currently displayed product.
product = await $w("#dynamicDataset").getCurrentItem().nombre_emp;
// Check if the current product is in the wishlist and act accordingly.
checkWishlist();
// Set the action that occurs when the login message is clicked to be the loginMessageClick() function.
$w('#loginMessage').onClick(loginMessageClick);
});
// Check if the current product is in the wishlist and act accordingly.
async function checkWishlist() {
// If the current user is logged in:
if (wixUsers.currentUser.loggedIn) {
// Query the "FAVOTITE DB" collection to find if the product was already added to the user's wishlist.
let wishListResult = await wixData.query("Favoritos_DB")
.eq("product", product)
.eq("userId", user.id)
.find();
// If the product was already added to the user's wishlist:
if (wishListResult.items.length > 0)
// Show the "inWishList" image with a fade effect.
$w('#inWishList').show('fade', { duration: 100 });
// If the product was not yet added to the user's wishlist:
else
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', { duration: 100 });
}
// If the current user is not logged in:
else {
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', { duration: 100 });
}
}
//-------------Event Handlers-------------//
// Set the action that occurs when the "inWishList" image is clicked.
export function inWishList_click(event, $w) {
// If the current user is logged in:
if (user.loggedIn)
// Remove the current product from the wishlist.
removeFromWishlist();
}
// Set the action that occurs when the "notInWishList" image is clicked.
export function notInWishList_click(event, $w) {
// If the current user is logged in:
if (user.loggedIn)
// Add the current product to the wishlist.
addToWishlist()
// If the current user is not logged in:
else
// Show the login message.
$w('#loginMessage').show();
}
// Set the action that occurs when the login message is clicked.
async function loginMessageClick() {
// Set the login options.
let options = { "mode": "login" };
// Hide the login message.
$w('#loginMessage').hide();
// Prompt the user to login using the options created above.
await wixUsers.promptLogin(options);
}
//-------------Wishlist Functionality-------------//
// Add the current product to the current user's wishlist and update the page accordingly.
async function addToWishlist() {
// Create the wishlist item relating the current product to the current user.
let wishListItem = {
product: product,
userId: user.id
};
// Hide the "notInWishList" image with a fade effect.
$w('#notInWishList').hide('fade', { duration: 100 });
// Show the "inWishList" image with a fade effect.
$w('#inWishList').show('fade', { duration: 100 });
// Insert the item created above into the "products-wishlist" collection.
let result = await wixData.insert("Favoritos_DB", wishListItem);
}
// Remove the current product to the current user's wishlist and update the page accordingly.
async function removeFromWishlist() {
// Query the "products-wishlist" collection to find the wishlist item corresponding to the current product and current user.
let wishListResult = await wixData.query("Favoritos_DB")
.eq("product", product._id)
.eq("userId", user.id)
.find();
// If a wishlist item was found:
if (wishListResult.length > 0) {
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', { duration: 100 });
// Hide the "inWishList" image with a fade effect.
$w('#inWishList').hide('fade', { duration: 100 });
// Remove the wishlist item from the "products-wishlist" collection.
await wixData.remove("Favoritos_DB", wishListResult.items[0]._id)
}
}
sorry for my bad english, am going to post my issue.