addToCart return error

I use next code:
$w.onReady( function () {
let item = $w(‘#dynamicDataset’).getCurrentItem();
$w(“#button7”).onClick(() => {
$w(“#widget8”).addToCart(item._id)
.then(() => {
console.log(“Product added”);
})
. catch ((error) => {
console.log(error);
});
});
});

item is correct and it has id
#button7 is a button,
#widget8 has CartIcon type

but click return undefined and not add to cart.
What’s wrong?

What do you mean widget is cart type? The addToCart can only be used on the shopping cart icon on your site, nowhere else. Try that.

I used CartItem element to call addToCart function.
I added shoppingCartIcon1.
Same error: click on “add to cart” return “undefined”

!200x196
!690x220

@shoppokapoka make sure you add a onReady wrapper for your Dataset, look in Reerence API for dataset then onReady. I think you don’t have anything in the item so add that

@andreas-kviby Added. Same :frowning:

Hi @shop.pokapoka

have you found the answer? I am having the same issue