Liquid, JavaScript, themes, sales channels
When using the /cart/change.js endpoint, updating a cart item's properties is not working when selecting by variant id. It doesn't produce an error, just doesn't update the properties
jQuery.post('/cart/change.js', { properties: { test: 'b'}, id: '37667537027267' })
Updating the quantity by id works
jQuery.post('/cart/change.js', { quantity: 2, id: '37667537027267' })
Updating properties using line numbers works
jQuery.post('/cart/change.js', { properties: { test: 'b'}, line: 1 })
And updating using the item key works
jQuery.post('/cart/change.js', { properties: { test: 'c'}, id: '37667537027267:d157c19aee0c9bc16e6ec4c4299341ff' })
Any ideas what might be causing this issue and how to fix it?
Solved! Go to the solution
This is an accepted solution.
If you have 2 items (same variant ID) in the cart and one has line item properties and one doesn't or they have different line item properties, they are treated as different line items in the cart. So in this case, if you tried to target by variant ID, it wouldn't know which one to change. That's why you need to use the line number or the key, as they are unique per line item.
This is an accepted solution.
I think the documentation is confusing. First it says you can use id, line or key. Then it says if you need to handle multiple items with same variant_id use line. But it is never mentioned that you can't use id to update properties even with a SINGLE item in cart.
Hi,
You can only update by 'line' or 'id'
Hi,
Yes I know and as I explained above making the update by line works, but that still doesn't explain why updating by id doesn't work
same issue
This is an accepted solution.
If you have 2 items (same variant ID) in the cart and one has line item properties and one doesn't or they have different line item properties, they are treated as different line items in the cart. So in this case, if you tried to target by variant ID, it wouldn't know which one to change. That's why you need to use the line number or the key, as they are unique per line item.
Hey,
sorry, but your quote from the documentation doesn't answer the original question.
The original question was why it doesn't work using the variant ID, and I explained that. What am I missing?
what you posted makes sense. but if you try with only ONE item in cart it still won't work. So it seems like no matter how many line items in a cart you have, combination of item.id and properties doesn't work
Yeah, I was just illustrating why Shopify set it up to not work with the variant ID. It's not a situational thing, it's just how they made it work.
This is an accepted solution.
I think the documentation is confusing. First it says you can use id, line or key. Then it says if you need to handle multiple items with same variant_id use line. But it is never mentioned that you can't use id to update properties even with a SINGLE item in cart.
This is a very good point, I've been trying to use variant id based on the documentation.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024