Coding for wish list

Hello!

I have a problem creating a wish list for my site. The thing is that once I click “Add to list”, nothing happens. I have two buttons and the first one is “Add to list” (it’s not linked) and the second one is “view list”. The second one is linked to a page called “My List”. Once an item has been added, there should be a text showing “Success! Item has been saved”, but nothing happens. Here is my code:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
let user;
var userID;
let itemObj;
var product_name;

$w.onReady(function () {
$w(“#dynamicDataset”).onReady(() => {
product_name = $w(“#text31”).text;
});

user = wixUsers.currentUser; 
userID = user.id; 
let isLoggedIn = user.loggedIn; 
if (isLoggedIn == true) { 
	$w("#dynamicDataset").onReady(() => { 
		testwish(product_name); 
	}); 
} else { 
	wixUsers.promptLogin() 
} 

});

function testwish() {
let userId = user.id;
wixData.query(“List”)
.eq(“title”, product_name)
.eq(“userId”, userId)
.find()
.then((results) => {
let count = results.totalCount;
if (count == 0) {
$w(“#button1”).label = “ADD TO WISH LIST”;
} else {
$w(“#button1”).label = “REMOVE FROM WISH LIST”;
}
});
}

function dothewish() {
let userId = user.id;
wixData.query(“List”)
.eq(“title”, product_name)
.eq(“userId”, userId)
.find()
.then((results) => {
let items = results.items;
let firstItem = items[0];
let count = results.totalCount;
if (count == 0) {
let toSave = {
“productId”: product_name,
“userId”: userId
};
wixData.save(“wishlist”, toSave)
$w(“#button1”).label = “REMOVE FROM WISH LIST”;
} else {
wixData.remove(“wishlist”, firstItem._id);
$w(“#button1”).label = “ADD TO WISH LIST”;
}
});
}

export function addtowishlist_onclick() {
dothewish(product_name);
}

Thanks!

Hi,
I don’t see anywhere in your code that you’re displaying the success message. Please make sure you add that after the save() call.

change the “export function addtowishlist_onclick”
to export function button1_onclick
and add onclick event on the properties menu of #button1

recently i am working on the same code but i have other problem
when i click on the “add to list button” it’s find the item and add to my wishlist database, as i want but it’s not showing at my wish list page