400 error when removing item from cart

New Member
2 0 0

Hey all, 

 

Having a major issue with removing items from the cart. 

If you add 1 item and remove it an alert pops up saying 'cannot update empty cart(bad_request): null' and then the popup shuts and the regular cart page is loaded. 

If you add more than 1 item to the cart and remove of them the alert says 'no valid id or line parameter(bad_request): null' and then once again the popup shuts and the regular cart page is loaded. 

 

I am at my absolute wits end with this, we have made a lot of updates to our theme but I can't see that any of them would have made this such an issue. 

Here is a pastebin of the cart.liquid: https://www.pastiebin.com/5dfce3b422211

Here is a product from our site that you can add to the cart to test: https://changingthepresent.org/collections/gina-gibney-dance-inc/products/gina-gibney-dance-inc-8-se...

 

0 Likes
Shopify Expert
2676 65 665

Katie, try this:

in your theme.js asset  there is this code (I've removed some code for brevity):

    // Completely remove product
    $('.ajaxifyCart--remove').on('click', function(e) {
... e.preventDefault(); updateQuantity(line, qty); });

modify it like this:

    // Completely remove product
    $('.ajaxifyCart--remove').on('click', function(e) {
...
      e.preventDefault();
      updateQuantity(line, qty);
      return false;
    });

This should stop your errors. (Potentially may break something else, so please test thoroughly).

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes
New Member
2 0 0

Thanks! It did work and I'll be sure to test it thoroughly.

 

I work on another store with the same theme that doesn't have that return statement but doesn't have any errors which is confusing. Would you mind explaining how you knew that would stop the errors?

Thanks again! 

0 Likes
Shopify Expert
2676 65 665

This can be a result of an app, as they tend to add a lot of javascript code, sometimes affecting the theme code too.

It looked to me like some code is trying to remove the product twice from the cart.

The theme includes event.preventDefault but sometimes it's not enough any you need to stopImmediatePropagation and returning false does exactly this.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes