I am trying to add a product to cart with a click event on a button. I keep getting this error
I made productId a constant and copied the id from my products collection.
I also have no options for the product at the moment.
Can anyone help me?
I am trying to add a product to cart with a click event on a button. I keep getting this error
I made productId a constant and copied the id from my products collection.
I also have no options for the product at the moment.
Can anyone help me?
Steven, I have some code utilizing addToCart and thought I’d change a legitimate ID to a bogus one. It returned the very same error message. In order to rule this out as the culprit, you might re-check the ID that you are assigning to the constant. The alpha characters in the Wix Store product IDs are all lower case. I changed one letter from lower to upper case and received the error.
This issue doesn’t exist the id is copied straight from the products collection and all the characters are lowercase. I still need help.
@hernands16 Where in the code page is productId assigned. Post a screenshot of that, and perhaps something will be apparent to one of us.
Steven, looking at your code, there appears to be no reason why it should not add the item to the cart. However, something did catch my eye, though I may be reaching here. When I add an Add to Cart button, the one from the Store section of the elements list and not a button from the Buttons section, that button does not have a click event that you can add and its default name is “addToCartButton1”. In fact, it’s not a button element at all, but an iFrame. I’m wondering what would happen if you added a regular button. And then in a click event added from its property sheet, copy and paste your addToCart code from above into that function. Do you get the same error?
Yea that is what I had it doesn’t work. I feel like the program is having trouble fetching the product because it doesn’t know where to fetch the id from. I don’t know that is just my guess.
I’ve been stuck on this for over a month haha.
So many questions about it in many threads, and there is no answer to anyone about anything so basic.
Perhaps WIX deliberately objects to adding a product independently in the code.
Maybe someone can help how to add a product to the shopping basket with only the product ID.
let id= $w(‘#dynamicDataset’).getCurrentItem().muzarsal;
console.log(id);
$w(‘#myShoppingCartIcon’).addToCart(id)
.then( () => {
console.log(“Product added”);
} )
. catch ( (error) => {
console.log(error);
} );
This code is marked with an error. Write to me as follows:
‘addToCart’ does not exist on ‘#myShoppingCartIcon’
אופס. פשוט היה חסר לי את האלמנט של הסל. #myShoppingCartIcon