Shopify cart/update.js endpoint not updating the correct lineitem

Shopify cart/update.js endpoint not updating the correct lineitem

uvindus
Shopify Partner
2 0 1

I have run into this issue. There are several items in the cart with the same variant id, but different properties and discounts. I noticed that when I make a post request using the lineitem keys to the cart/update.js endpoint, it is not updating the correct line item. It's just updating the first item that has the variant id.. Any reason why this could happen?

For example, there are multiple lineitems with the variant id "40072319336547". When I run this

jQuery.post(window.Shopify.routes.root + 'cart/update.js', "updates[40072319336547:62a477719b1f798b23f1ce16199c1668]=3" );

It's not updating the line item with key "40072319336547:62a477719b1f798b23f1ce16199c1668". Just some other line item with the variant id 40072319336547.

Replies 3 (3)

Guleria
Shopify Partner
3186 620 891

Hello @uvindus ,


try with this one

      $.ajax({
        url: '/cart/change.js',
        type: "post", 
        dataType: 'json',
        data: { 
          "line": index, // 'index' unique value 
          "quantity": qty, // 'qty' Quantity
          "properties": propertydata, // 'propertydata' data array which you want to update in line

        },  
        success: function(cart){ location.reload();  }
      });
- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me. - Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
- Support me PayPal
uvindus
Shopify Partner
2 0 1

Hi @Guleria Thanks for your response. Unfortunately, I am trying to update multiple line items in a single request, so I have to use update.js 

Guleria
Shopify Partner
3186 620 891

 

okay
btw if you want to see working example with the code I shared check here    

Select a variant, click 'atc' fill the line items in popup you can add multiple, hit the button.
Now once a product is added to the cart, in the cart page click the edit icon. Here I'm using the same code I shared last day. 

- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me. - Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
- Support me PayPal