0

I want to clear all shopping carts from database and start from scratch. But I don't want to create problems in database for my customer accounts or store orders. I just want to remove all carts which are abandoned.

I am thinking to use this queries in database:

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE TABLE `quote`;
TRUNCATE TABLE `quote_address`;
TRUNCATE TABLE `quote_address_item`;
TRUNCATE TABLE `quote_id_mask`;
TRUNCATE TABLE `quote_item`;
TRUNCATE TABLE `quote_item_option`;
TRUNCATE TABLE `quote_payment`;
TRUNCATE TABLE `quote_shipping_rate`;

SET FOREIGN_KEY_CHECKS=1;

Will these do my job? Or I break everything?

2

I put together an extension which deletes old quotes

https://github.com/DominicWatts/QuoteCleaner

Can trigger through console or let magento cron task handle it

crontab.xml

https://crontab.guru/#*/25_*_*_*_*

  • Dominic great extension!! Tell me something....I see cron folder. So you don't have to run the script. Just to configure settings in admin,right? – G. G. Jun 21 at 18:28
  • You can either run it manually or let magento cron task handle it. I set it at every 25th minute crontab.guru/#*/25__** but you can edit crontab.xml to do what you want. I just chose something at random. – Dominic Xigen Jun 21 at 18:38
  • Great Job!!! Thank you!....I am also checking your repositories.....It is very good to have people like you in this community – G. G. Jun 21 at 18:41
1

I suggest you to use this query:

DELETE FROM quote WHERE quote.is_active = 1;

This query will delete only the active quotes (abandoned carts). This query will also delete related information in other quote.* tables thanks to "ON DELETE CASCADE" option.

Inactive quotes (with is_active = 0) are, usually, carts that have been converted to orders.

  • to understand if I also run DELETE FROM quote WHERE quote.is_active = 0; will also remove the inactive carts? I want to clear all carts. – G. G. Jun 21 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.