3

I've done some orders through Magento however I want to remove them now from Sales page to clean it up. I need to remove only test orders, there are also some real order which I don't wish to remove.

What approach shall I take?

Thanks

11
  • 1
    Possible duplicate of Magento 2: How to truncate customers, products, reviews and orders table
    – Piyush
    Commented Feb 27, 2018 at 11:01
  • Unfortunately not. I have real orders in the database I don't wish to remove. Plus I only wish to remove the orders. Not products, not reviews, just the orders.
    – zcoyne
    Commented Feb 27, 2018 at 11:02
  • then you have to delete test orders manually, or you can delete the test orders by id in a script
    – Piyush
    Commented Feb 27, 2018 at 11:03
  • Can you please explain HOW to remove delete the test order manually? I'm unsure hence why I asked the question. Thanks
    – zcoyne
    Commented Feb 27, 2018 at 11:04
  • there are extensions available to delete orders, you have to use one of them
    – Piyush
    Commented Feb 27, 2018 at 11:06

2 Answers 2

1

Tested in Magento 2.1.0

Be safe : make a backup of your sql first.

Use the sql below according to your needs :

SET FOREIGN_KEY_CHECKS=0;

# Clean order history
TRUNCATE TABLE `sales_bestsellers_aggregated_daily`;
TRUNCATE TABLE `sales_bestsellers_aggregated_monthly`;
TRUNCATE TABLE `sales_bestsellers_aggregated_yearly`;

# Clean order infos
TRUNCATE TABLE `sales_creditmemo`;
TRUNCATE TABLE `sales_creditmemo_comment`;
TRUNCATE TABLE `sales_creditmemo_grid`;
TRUNCATE TABLE `sales_creditmemo_item`;
TRUNCATE TABLE `sales_invoice`;
TRUNCATE TABLE `sales_invoiced_aggregated`;
TRUNCATE TABLE `sales_invoiced_aggregated_order`;
TRUNCATE TABLE `sales_invoice_comment`;
TRUNCATE TABLE `sales_invoice_grid`;
TRUNCATE TABLE `sales_invoice_item`;
TRUNCATE TABLE `sales_order`;
TRUNCATE TABLE `sales_order_address`;
TRUNCATE TABLE `sales_order_aggregated_created`;
TRUNCATE TABLE `sales_order_aggregated_updated`;
TRUNCATE TABLE `sales_order_grid`;
TRUNCATE TABLE `sales_order_item`;
TRUNCATE TABLE `sales_order_payment`;
TRUNCATE TABLE `sales_order_status_history`;
TRUNCATE TABLE `sales_order_tax`;
TRUNCATE TABLE `sales_order_tax_item`;
TRUNCATE TABLE `sales_payment_transaction`;
TRUNCATE TABLE `sales_refunded_aggregated`;
TRUNCATE TABLE `sales_refunded_aggregated_order`;
TRUNCATE TABLE `sales_shipment`;
TRUNCATE TABLE `sales_shipment_comment`;
TRUNCATE TABLE `sales_shipment_grid`;
TRUNCATE TABLE `sales_shipment_item`;
TRUNCATE TABLE `sales_shipment_track`;
TRUNCATE TABLE `sales_shipping_aggregated`;
TRUNCATE TABLE `sales_shipping_aggregated_order`;

# Clean cart infos
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`;

# Reset indexes (if you want your orders number start back to 1
TRUNCATE TABLE sequence_invoice_1;
TRUNCATE TABLE sequence_order_1;
TRUNCATE TABLE sequence_shipment_1;
TRUNCATE TABLE sequence_creditmemo_1;


SET FOREIGN_KEY_CHECKS=1;

DO NOT TRUNCATE / EMPTY THE FOLLOWING :

  • sales_order_status
  • sales_sequence_meta
  • sales_sequence_profile
  • sales_order_status_label
  • sales_order_status_state

Thank you

2
  • Thsi works perfectly in 2.3.7. Needs more upvotes
    – ItsJhonny
    Commented Jun 3, 2021 at 13:57
  • Thank you Happy to help Commented Jun 4, 2021 at 10:28
1

Removing Sample Data can easily be done through Database Queries.

I wrote a Codeblog about it which you can find here:

https://codeblog.experius.nl/magento-2-remove-sample-data-test-data/

It also contains Enterprise (Commerce) queries.

0

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