Hello ladies and gentlemen,
On a dynamic page I have a repeater that displays the data from the “products” collection.
There is a border that allows you to select each product.
At the bottom of the page, an “addToCart” button that allows you to add the selected products to cart.
I do not have any error messages in my console or in the code.
Who will find the error in this code and prevent it from working ?
I was inspired by this one : https://support.wix.com/en/article/wix-code-adding-multiple-items-to-the-cart-in-a-wix-stores-site
I want to say that I am not a developer, I learned everything from your contributions on Wix code and thank you for that.
Excuse me if my english is faulty.
The Code ===>
import wixData from 'wix-data';
const selectedProducts = [];
export function repeater1_itemReady($w, itemData, index) {
$w('#addToCartButton').enable();
$w('#imageProduct').onClick(() => {
selectedProducts.push(itemData);
$w('#productBorder').show();
const indexOfProduct = selectedProducts.findIndex(item => item._id === itemData._id);
selectedProducts.splice(indexOfProduct, 1);
$w('#productBorder').hide();
});
}
export async function addToCartButton_click(event, $w) {
selectedProducts.forEach(async product => {
await $w('#shoppingCartIcon').addToCart(product._id)
.then(() => {
console.log("add product ${productId} success");
})
.catch((error) => {
console.log("Error: ${error.stack}");
});
});
}
#addToCartButton #shoppingCartIcon #repeater #dataset #store