Add To Cart button on a repeater

I created a product list page with a repeater. It is connected to wix Products/Stores dataset.(#dataset2)
The product information fields are connected to a custom database collection (“360precisionproducts”) to retrieve the unique product info.

Below is my code which I couldn’t get to work.
Hope someone can help.
Thanks.

$w.onReady( function () {
$w("#cartButton").onClick( (event) => {
let $item = $w.at(event.context); // Get container scope
let selectedProduct = $item('#dataset2').getCurrentItem();
let productId = selectedProduct._id;
$w('#shoppingCartIcon1').addToCart(productId)
.then(() => {
// Item added to the shopping cart
console.log("add product ${productId} success");
})
.catch((error) => {
// Catch an error that occurs
console.log("Error: ${error.stack}");
});
} );


Hey,

There is a similar post, I think this might be what you are looking for:

https://www.wix.com/corvid/forum/community-discussion/add-button-to-add-to-cart

Good luck!

Thank you my code was taken and modified from the same post but still didn’t help connecting the Add To Cart button to the right item that comes from a custom database collection. The same items exist in the Products database. Just trying to figure out how to link the two so the button picks the right item from the containers.
Thanks.

i have same issue please wix help

Please open a new post with your question, it’s against the Community Guidelines to bump old posts with questions.

@ahmadnasriya i think u should give as an answer not again community or close without help

@angeloosa2 P lease observe the community guidelines and refrain from multiple posts on the same topic or question. Please add your own issue into a new post instead of bumping up an old post.