Hey Corvid Community! I’m having some issues with shopping cart API, and would appreciate if anyone else has experienced this and can help with solving it. I want this button:
to open the MiniCart and add the book to it. I’ve got the code working, except that I always have to click the button twice for it to add to and open the cart.
Here’s my code:
export function button40_click(event) {
$w("#button40").onClick(() => {
$w("#shoppingCartIcon1").addToCart("dc53f4da-00a8-4b8b-4649-f6a8fbe1acce")
.then(() => {
console.log("Product added");
})
});
}
Thanks in advance!
You don’t need both of these lines as they are doing exactly the same thing and probably causing your double click issue. Just delete the second line and it should all be fine to go, although you might need to delete a closing } as you have deleted an opening { when deleting the second line.
https://www.wix.com/corvid/reference/$w.CartIcon.html#addToCart
export function button40_click(event) {
$w("#button40").onClick(() => { // remove this line
Just so you know and understand.
export function button40_click(event) {
Is when you add an event handler through the properties panel for your required element.
$w("#button40").onClick(() => {
Is the same as the code above, however the event handler is written into the code itself so that you do not need to then add it through the properties panel for that element too.
Great, thanks for your help!