728x90-banner.png

How to delete orders from Magento backend sales figures

July 20, 2009 · View Comments

In the beginning of my Magento WebStore experience, I had many test orders that I would submit to test out features and tweaks that I had implemented into my web store. However, this was often done after the site had already gone live, and I couldn’t necessarily just empty my entire database file via phpMyAdmin, otherwise I would lose all that data. So the question became “How can I remove these test orders from my sales figures, but not mess with the legitimate sales and data that I wanted to keep?” This is where a good knowledge of SQL comes in. Most Magento users really don’t even take into account that everything is stored in a database and can be hand-edited via phpMyAdmin, but it is and can.

To remove an order, no matter what its status, all you need is access to be able to execute SQL querys (usually via phpMyAdmin) and some specific info about the order in question. Specifically, the order number is what you need the most (the more data the better – that way you can be SURE that you are removing the expected order.)

Once you have your order number, and you are connected to your Magento SQL Database, execute the following command to verify that that is the order that you want to delete. This should be clear, but in case it isn’t, you need to replace INSERT_ORDER_NUMBER_HERE with your order number.

select * from `sales_order` where `increment_id` = INSERT_ORDER_NUMBER_HERE ; 

Check the output of that query, and make sure that the order number is indeed for the order you want to delete. Once verified, execute the following command. (Please note, SQL commands cannot just be ‘undone.’ There are precautions you should take before you EVER do SQL querys on a live site database. Namely, backup your database files! More info on that coming soon.)

delete from `sales_order` where `sales_order`.`increment_id`= INSERT_ORDER_NUMBER_HERE limit 1 ; 

Enjoy!

  • Kunalray
    hello, I just wanted to say that I really enjoyed your site and this post. You make some very informative points. Keep up the great work. I found some related information here- http://store.modulesoft.in/manage-orders-by-orderbook.html
  • Modulesoft
    You can easily Manage your orders and delete it via Magento Order Book Extension;
    search for Magento order book extension in magento website
  • bee
    Hi,
    I am pretty sure that this sql can cause u a lot of damage.
    each order in the DB connected to 10+ tables in the backend reports/orders/invoices...
    So each time u delete using this query i believe u making some kind of damage in the backend.

    http://sex.bee.co.il
    חנות סקס, ויברטור, ויברטורים
  • Magento Designer is right, it is in the report_event table, but you can sort it as well. To sort the report_events table by most viewed events, (there are 6 different event types), use this command:

    SELECT * FROM `report_event` where `event_type_id` = 1 ;

    and then you can delete whichever items/events you want. to clear the entire most viewed events, and nothing else, use the following command:

    DELETE * FROM `report_event` where `event_type_id` = 1 ;

    I will write up a full post about this later. Thanks for the idea Magento Designer. I am sure that there is a way to use this sql to delete individual items view count.
  • For others looking for removing 'most viewed' data: had to remove records from report_event - just for info. Cheers
  • Surely - this is one of the missing features of Magento. Hvae also tried the extension + SQl truncate script from Elias Interactive - however, there is no clean way to do this it seems - partly because of the complex database

    Where is "mostly viewed products" data stored btw. Ideas? (no hijacking intended - just havent been able to figure it out yet - and it relates to test data cleanup process)
  • Thanks a lot. Was looking for this.
    Although it's a bit redundant, since it is for testing purposes only, it does its job.
  • ch3ckmat3
    Well thanks Admin, but i was wondering that your method deletes all the related records in the database i.e. invoices, shipments and credit memos etc.

    plz confirm.
  • Well check this, a total solution for deleting Magento order “Delete Any Order”

    https://www.yireo.com/software/delete-any-order
  • Why not just use the delete order extention?
  • Because from my understanding, the delete order extension only allows you to delete orders that are marked as "canceled" and nothing else. My method allows you delete any order, regardless of order status.

    Thanks for the suggestion though, I had looked into it. I'll check again and see if they've updated theirs.
blog comments powered by Disqus

Previous post:

Next post: