Solved

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

NegativeSpace
Shopify Partner
18 3 6

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?

Accepted Solutions (2)
gina-gregory
Shopify Expert
742 51 211

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.

View solution in original post

Illia_Kuzma
Shopify Partner
36 2 14

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.

View solution in original post

Replies 10 (10)

Jivan_Suhagiya
Shopify Partner
581 79 124

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
NegativeSpace
Shopify Partner
18 3 6

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
Shopify Partner
36 2 14

same issue

gina-gregory
Shopify Expert
742 51 211

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
Shopify Partner
36 2 14

Hey,

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

gina-gregory
Shopify Expert
742 51 211

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

Illia_Kuzma
Shopify Partner
36 2 14

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
742 51 211

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.

Illia_Kuzma
Shopify Partner
36 2 14

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.

Codesto1
Shopify Partner
26 3 2

This is a very good point, I've been trying to use variant id based on the documentation.