Skip to content

Instantly share code, notes, and snippets.

@kevincal
Last active March 16, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincal/0573cbd9594abed1c4e9b18d320c7275 to your computer and use it in GitHub Desktop.
Save kevincal/0573cbd9594abed1c4e9b18d320c7275 to your computer and use it in GitHub Desktop.
SQL to delete old Magento Abandoned Cart Entries: Quote (sales_flat_quote), Quote Item (sales_flat_quote_item), Quote Item Options (sales_flat_quote_item_option), Quote Address (sales_flat_quote_address), and Quote Payment (sales_flat_quote_payment). Does not clear out sales_flat_quote_address_item but you can follow same logic.
DELETE FROM sales_flat_quote_shipping_rate WHERE address_id IN (
SELECT a.address_id
FROM sales_flat_quote q, sales_flat_quote_address a
WHERE a.quote_id = q.entity_id AND q.created_at < '2016-12-31 23:23:59'
);
DELETE FROM sales_flat_quote_address WHERE quote_id IN (
SELECT quote_id FROM sales_flat_quote WHERE created_at < '2016-12-31 23:23:59'
);
DELETE FROM sales_flat_quote_payment WHERE quote_id IN (
SELECT entity_id FROM sales_flat_quote WHERE created_at < '2016-12-31 23:23:59'
);
DELETE FROM sales_flat_quote_item_option WHERE item_id IN (
SELECT i.item_id
FROM sales_flat_quote q, sales_flat_quote_item i
WHERE i.quote_id = q.entity_id AND q.created_at < '2016-12-31 23:23:59'
);
DELETE FROM sales_flat_quote_item WHERE quote_id IN (
SELECT entity_id FROM sales_flat_quote WHERE created_at < '2016-12-31 23:23:59'
);
/*
DELETE FROM personalize WHERE quote_id IN (
SELECT entity_id FROM sales_flat_quote WHERE created_at < '2016-12-31 23:23:59'
);
*/
DELETE FROM sales_flat_quote WHERE created_at < '2016-12-31 23:23:59';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment