Jump to content

SQL Delete all abandoned cart after 1 hour


Recommended Posts

Hello,

 

I'm trying to delete the cart older than 1 hour with the following query:

$sql = "DELETE psez_cart_product FROM psez_cart_product JOIN psez_cart ON psez_cart.id_cart = psez_cart_product.id_cart WHERE DATE(psez_cart.date_add) < DATE_SUB( NOW( ) , INTERVAL 1 HOUR)";

and 

$sql = "DELETE FROM psez_cart WHERE DATE(psez_cart.date_add) < DATE_SUB( NOW( ) , INTERVAL 1 HOUR)";

but the condition doesn't work, it is always executed.

 

What am I doing wrong?

 

Thank you!

Link to comment
Share on other sites

Please remember that when a cart ends with an order it still must be there in the database. If you delete the cart, you can break the order and make some mess.

 

So first you should distinguish between abandoned cart and ordered cart.

 

And if you have that cart, you should use some PHP script with $cart->delete() to make sure that everything gets properly deleted.

 

Check out the Prestashop Tidy module, it has a cron task to delete old abandoned carts. It uses a days interval, but you can make a small code adapt to make it an hour. 

Link to comment
Share on other sites

Why you don't delete the carts from back-office ? Tab "customers -> shopping carts"

Cart is some complicated thing, cause interacts with several database tables (dependencies), I suggest you to do not remove it manually from database. If you forget something you crash the ID dependencies.

 

BTW why the carts are making troubles ? There should be not so much abandoned carts in a week available, UNLESS you didn't changed any code (by override or not) or are using a theme which is causing mass abandoned carts made by SERP's (cookie session problem). If you run Prestashop native, so there on controller are precautions coded to avoid carts from SERP's.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...