POST /cart/change.js using line_item.key instead of only variant_id

New Member
2 0 0

I'm trying to POST /cart/change.js updating my line item's quantity using line item's key instead of just the variant ID as shown here: https://help.shopify.com/en/themes/development/getting-started/using-ajax-api#change-cart

 

Reason because I have multiple customized item (same variant ID) with different properties in the cart and If i use only variant ID, it will change all with similar variant ID.

 

I could update the quantity if i use just the variantID, but it does not work if i use line_item.key instead. where did I went wrong? 

I've assigned gcidcode = line_item.key

I tested {{ gcidcode }} and it display properly on the webpage Eg: 794864053:70ff98a797ed385f6ef25e6e974708ca

Shopify.Cart.GiftWrap.change = function() {
  jQuery.ajax({
    type: 'POST',
    url: '/cart/change.js', 
    data: { quantity: 1, id: {{ gcidcode }} }, 
    dataType: 'json',
    success: function() { location.href = '/cart'; }
  });
}

If I assign gcidcode = line_item.variant_id, with the above jQuery, it will update the quantity properly, but it doesn't seems to work with line_item.key.

0 Likes
Shopify Staff
Shopify Staff
293 6 33

Hi, @briantan26 

 

Elle here from Shopify.

 

I've moved your post from the Technical Q&A board to our API board as it should receive a better response here.


Cheers,

Elle

Elle | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

0 Likes
Highlighted
Community Manager
Community Manager
499 23 54

Hi @briantan26,

 

What's the error you are seeing? I was able to update quantity using the /cart/change.js endpoint with the following call.

 

jQuery.post('/cart/change.js', { quantity: 5, id: '419432426:1c668117300fdaca18c1a4ad36aeb041' });

Can you give that a try and let me know if you still encounter issues?

 

Cheers,

0 Likes