theme-scripts icon indicating copy to clipboard operation
theme-scripts copied to clipboard

No api to add multiple items to cart

Open umxr opened this issue 2 years ago • 3 comments

There doesn't seem to be an API to add multiple items to the cart, is this something that is planning on being added. I know this is supported by the /cart/add route. the dev docs validate this. https://shopify.dev/api/ajax/reference/cart#post-cart-add-js. I'll be more than happy to pick this up.

umxr avatar Oct 20 '21 13:10 umxr

This functionality is still missing in 2023!

kyrylo-soulandwolf avatar Jan 30 '23 05:01 kyrylo-soulandwolf

@kyrylo-soulandwolf On Shopify you've been able to add multiple items at once since the very beginning of the Cart API. Items is an array, so you can always send multiple items with the variant ID to add many at once.

let formData = {
 'items': [
    {
      'id': 36110175633573,
      'quantity': 2
    },
    {
      'id': 36110175633581,
      'quantity': 1
    },
  ]
};

fetch(window.Shopify.routes.root + 'cart/add.js', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(formData)
})
.then(response => {
  return response.json();
})
.catch((error) => {
  console.error('Error:', error);
});

jonathanmoore avatar Jan 30 '23 20:01 jonathanmoore

@jonathanmoore so what's the point of theme-cart package if adding multiple items needs to be done by hand? the problem isn't about Shopify API not supporting it, but having a package that doesn't support all the functionality provided by the API.

kyrylo-soulandwolf avatar Feb 14 '23 11:02 kyrylo-soulandwolf