Add multiple item at a time to cart

Hello there!
i am adding multiple items to cart at a time but this is not working as expected.
Case :
when i am adding two items then the both item added to cart twice, same as when i am adding three item in the cart then the all three items are added thrice.
can anyone please help me with this ?
thanks in advance.

Which version of VSF are you using? You should wait till the item has been added if you’re adding multiple items or pass them via array to addToCart (accepts multiple items)

      const productsToAdd = []
      for (const item of products) {
        const product = await this.$store.dispatch('product/single', { options: { sku: item.sku }, setCurrentProduct: false, selectDefaultVariant: false })
        product.qty = item.qty_ordered
      await this.$store.dispatch('cart/addItems', { productsToAdd })
1 Like

Hi @pkarw

I am wondering why you need to loop over all products and load them with this.$store.dispatch('product/single', ... before using this.$store.dispatch('cart/addItems', ...?
Could I not just use addItems with the initial products array?