0

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);
                }
            });
        });
    });
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

0

This code is required to make sure the items don't stack in the cart. In v3, to make the item unstackable you can use the data-item-stackable property set to never.

Dharman
  • 30,962
  • 25
  • 85
  • 135
lea
  • 56
  • 3
  • Thank you Lea for your time and effort, but the love of me setting data-item-stackable: "never" does absolutely nothing. Maybe the problem is that although I'm using snipcart.js version 3.0.30. my dashboard is always reminding me that I'm still using version 2 and that I should migrate. That's another issue though. –  Mar 03 '21 at 04:19