/cart/update.js api broken after subscriptions introduction.

greg12
Excursionist
36 1 7

Be careful when use /cart/update.js.Documentation says that to update cart you have to POST on /cart/update.js payload of the form { update : { id : quantity} }. But what happen in special case when you have both product and subscription for this product in the cart? Let me describe. So lets say you have product Ananas and you created sellingPlan on top of Ananas. You added both to cart. Now you check your cart.json , and you see scary things, in items array you have two items with same id. So what happen when you try to update the quantity using this id in the payload? Product OR subscription will be update, ONLY ONE. Depends which one was added to the cart. Fortunately i found the way out of this madness. There is unique identifier of each it, it is `key` which is of the form `id : itemHash`. Documentation says nothing about this, at least documentation of cart api, in liquid docs you can find it https://shopify.dev/api/liquid/objects/line_item. It is a bit scary to build logic based on undocumented api but at least it works. 

Replies 0 (0)