addToCart function is not wokring

const currentProduct = $w( ‘#dynamicDataset’ ).getCurrentItem()._id;
console.log(currentProduct);
// Add the current product to the cart with the user’s chosen background color, text color, custom text, and custom background image.
$w( ‘#shoppingCartIcon1’ ).addToCart(currentProduct._id, {
“choices” : {
//“Background Color”: $w(‘#colorText’).text,

    }, 

“customTextFields” : [{
“title” : “Custom Text” ,
//“value”: $w(‘#textInput’).value
},
{
“title” : “Background Image” ,
“value” : $w( ‘#print’ ).src
}
]
});

Hi,

In the code you provided it seems you’re missing an onClick() function on a button that will trigger the product to be added to the #shoppingCartIcon element.

You can take a look at my example below:

$w.onReady(() => {
    $w("#button1").onClick(() => { 
        $w("#shoppingCartIcon1").addToCart("product._id")
            .then((results) => {
                console.log(results);
                console.log("Product added");
            })
            .catch((error) => {
                console.log(error);
            });
    })
})

Hope this helps you out. Let us know if it’s still not working for you!

Best regards,
Miguel | Corvid Team