Cart AJAX API /cart/change.js updating properties by id not working

Solved
NegativeSpace
Excursionist
18 3 5

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?

Jivan_Suhagiya
Shopify Partner
498 68 107

Hi,
You can only update by 'line' or 'id' 

If helpful then please Like and Accept Solution.
Email: suhagiyajivan1992@gmail.com
Skype: jivan.suhagiya
First kind of Checkout Reminder APP: https://apps.shopify.com/checkout-reminder
0 Likes
NegativeSpace
Excursionist
18 3 5

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

Illia_Kuzma
Excursionist
22 2 4

same issue

0 Likes
gina-gregory
Shopify Expert
710 48 176

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.

Illia_Kuzma
Excursionist
22 2 4

Hey,

sorry, but your quote from the documentation doesn't answer the original question.

0 Likes
gina-gregory
Shopify Expert
710 48 176

The original question was why it doesn't work using the variant ID, and I explained that. What am I missing?

0 Likes
Illia_Kuzma
Excursionist
22 2 4

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

gina-gregory
Shopify Expert
710 48 176

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.

0 Likes
Illia_Kuzma
Excursionist
22 2 4

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.