Forum

Thread tagged as: Problem, Runway, Shop

Empty Cart function doesn't empty cart until clicking 'update' cart.

Minor issue, no errors involved. Seems to be something that's changed in Perch, as I had this working previously and I haven't changed code involved.

I'm using latest version of Runway 3 and Shop. Everything is fine, site has just launched actually after a long time on ice due to friend's business not being ready.

On cart page, clicking "empty cart" calls page with nothing in it except the following...

<?php perch_shop_empty_cart(); ?>

Previously I was calling the above with AJAX, then using javascript to reload the cart page and produce the empty cart. Worked fine, but now the cart holds on to the items until "update cart" is used. Manually browsing to that page and then manually refreshing cart page still keeps items in cart until cart updated, so the issue is not related to AJAX. I suspect this problem happens any time we call this function and expect the cart to empty, like after a purchase.

If this is not happening for anyone else, I guess I'll dig a bit deeper on my side, or just remove the empty cart button (not a critical thing).

P K

P K 0 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you checked the debug output on the page where you're emptying the cart?

P K

P K 0 points

No errors in output debug on cart page before or after clicking empty cart. It does say "using cart from cache" in the output, which I'm guessing is normal.

If I append a query string to the end of the cart page URL like this "/shop/cart?123" the cart empties immediately (after clicking 'empty cart'). But if I go back to /shop/cart and refresh page, the items are still there for about 2 or 3 minutes before finally emptying upon refresh.

P K

P K 0 points

I reverted cart template back to defaults that come with perch but no luck, the same 2 minute wait on emptying cart happens when using the empty cart function.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's really odd. Are you making a GET request or a POST request? I wonder if this is just caching.

P K

P K 0 points

That was it. Problem solved. I mistakenly thought that "cache:false" was all I needed in the Jquery Ajax call. But that's still a GET. The following does the trick...

$.ajax({
    type: "POST",
    url: "/shop/empty-cart"
})