I'm trying to replicate a very nice tutorial on how to have each item in its own row in the cart. You can find it on this link. Unfortunately, this tutorial is using Snipcart v2 and I was hoping to get it working with v3.
The problem I'm facing is that adding the item to the cart is endlessly repeating. I'm not sure but I'm guessing that it has to do with item.adding
event triggering upon each item added with Javascript SDK.
Since Snipcart has no support, apart from one simple sentence per week, I was hoping to find a kind soul here, willing to help me.
This is my code:
document.addEventListener('snipcart.ready', () => {
Snipcart.events.on('item.adding', (item) => {
var quantity = item.quantity;
item.quantity = 1;
var products = new Array(quantity).fill({
id: item.id,
name: item.name,
price: item.price,
url: item.url,
customFields: item.customFields,
quantity: item.quantity,
stackable: "never"
});
products.forEach(async product => {
try {
await Snipcart.api.cart.items.add({
id: product.id,
name: product.name,
price: product.price,
url: product.url,
quantity: product.quantity,
customFields: product.customFields,
stackable: "never"
});
} catch (error) {
console.log(error);
}
});
});
});