Delete test orders in Magento

Delete test orders in Magento

You got a Magento project to develop, you created a Magento theme, you placed initial products and categories and you also placed some test orders to see if Shipping and Payment methods work as expected. Everything seems to be cool and the client wishes to launch the site. You launch it. When you enter the administration for the first time after the launch, you will see all your test orders there. You know those should be deleted. But how?
This is a new version of the same article.

If you try to delete orders in the backend, you will find out that you can only set the status to “cancelled” and the order is still there.  Unfortunately, Magento doesn’t enable us to delete those via administration, so you will not see any “Delete order” button. This can be quite frustrating both to developers and the merchants. People coming from an SAP world find the inability to delete to have some merit but there should be a status that removes the sales count from the reports i.e. sales, inventory, etc.

So, what to do?

You need to create php script in Magento root folder, copy this code into script and run script.

/**
 * @author Dejan Radic <dejan.radic@inchoo.net>
 */

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;"><div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"><h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

$mageFilename = 'app/Mage.php';

if (!file_exists($mageFilename)) {
    echo $mageFilename." was not found";
    exit;
}

require_once $mageFilename;

Mage::app();

$executionPath = null;

/*
 * determine Magento Edition
 */
if (file_exists('LICENSE_EE.txt')) {
    $edition = 'EE';
}elseif (file_exists('LICENSE_PRO.html')) {
    $edition = 'PE';
} else {
    $edition = 'CE';
}

if(($edition=='EE' && version_compare(Mage::getVersion(), '1.11.0.0.', '<')===true)
        || ($edition=='PE' && version_compare(Mage::getVersion(), '1.11.0.0.', '<')===true)
        || ($edition=='CE' && version_compare(Mage::getVersion(), '1.6.0.0.', '<')===true)
  ){
   $executionPath = 'old';
} else {
   $executionPath = 'new';
}

$xpathEntity = 'global/models/sales_entity/entities//table';

if ($executionPath == 'old') {
    $xpathResource = 'global/models/sales_mysql4/entities//table';
} else {
    $xpathResource = 'global/models/sales_resource/entities//table';
}

$salesEntitiesConf = array_merge(
    Mage::getSingleton('core/config')->init()->getXpath($xpathEntity),
    Mage::getSingleton('core/config')->init()->getXpath($xpathResource)
);

$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_write');

/*
 * If you want delete System/Order Statuses (Status and State) you
 * should comments below lines (46-51)
 */
$skipTables = array (
        $resource->getTableName('sales_order_status'),
        $resource->getTableName('sales_order_status_state'),
        $resource->getTableName('sales_order_status_label')
    );
$salesEntitiesConf = array_diff($salesEntitiesConf, $skipTables);

/*

Multiple RDBMS Support in Magento CE 1.6+ / EE 1.11+

http://www.magentocommerce.com/images/uploads/RDBMS_Guide2.pdf

2.2. Adapters:

... The new Varien_DB_Adapter_Interface was added to sign a contract that all
developed adapters must execute in order to get Magento working on an actual
database. The interface describes the list of methods and constants that can be used by resource models...

Used below in the loop:

 * If $executionPath == 'old'
    * Varien_Db_Adapter_Pdo_Mysql::showTableStatus()
    * Varien_Db_Adapter_Pdo_Mysql::truncate()
 * Else
    * Varien_Db_Adapter_Interface::isTableExists()
    * Varien_Db_Adapter_Interface::truncateTable()

*/

while ($table = current($salesEntitiesConf) ){
    $table = $resource->getTableName($table);

    if ($executionPath == 'old') {
        $isTableExists = $connection->showTableStatus($table);
    } else {
        $isTableExists = $connection->isTableExists($table);
    }
    if ($isTableExists) {
        try {
            if ($executionPath == 'old') {
                $connection->truncate($table);
            } else {
                $connection->truncateTable($table);
            }

            printf('Successfully truncated the <i style="color:green;">%s</i> table.<br />', $table);
        } catch(Exception $e) {
            printf('Error <i style="color:red;">%s</i> occurred truncating the <i style="color:red;">%s</i> table.<br />', $e->getMessage(), $table);
        }
    }

    next($salesEntitiesConf);
}

exit('All done...');

After you have it executed, the test orders will not be in the database any more. Keep in mind that this will delete ALL orders, in the database. So, you should execute this queries immediately after launch.

This script is tested on following Magento versions: 1.6.1.0 CE, 1.6.0.0 CE, 1.5.1.0. CE, 1.11.0.2 EE, 1.10.0.2 EE, 1.9.0.0 EE, 1.11.0.0 PE, 1.10.0.2 PE and 1.9.0.0 PE.
You can download script here.

100
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Dejan Radic

Magento Developer

At Inchoo, Dejan is a Magento back-end developer.

Other posts from this author

Discussion 100 Comments

1 2
Add Comment
  1. you can Easily Delete orders and manage all orders via Order book extension
    check this out
    http://www.magentocommerce.com/magento-connect/Modulesoft+Solutions/extension/4047/mspl_orderbook

  2. Unfortunately it doesn’t work in 1.4.1.1 :(

    It’s looking for ‘sales_order’ which doesn’t exist.

  3. found this one on a german site…… for magento 1.4.1.x

    i am going to try this on my test magento shop, will let you know if it worked….

    – Reset Magento TEST Data
    SET FOREIGN_KEY_CHECKS=0;
    – reset dashboard search queries
    TRUNCATE `catalogsearch_query`;
    ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;
    – reset sales order info
    TRUNCATE `sales_flat_creditmemo`;
    TRUNCATE `sales_flat_creditmemo_comment`;
    TRUNCATE `sales_flat_creditmemo_grid`;
    TRUNCATE `sales_flat_creditmemo_item`;
    TRUNCATE `sales_flat_invoice`;
    TRUNCATE `sales_flat_invoice_comment`;
    TRUNCATE `sales_flat_invoice_grid`;
    TRUNCATE `sales_flat_invoice_item`;
    TRUNCATE `sales_flat_order`;
    TRUNCATE `sales_flat_order_address`;
    TRUNCATE `sales_flat_order_grid`;
    TRUNCATE `sales_flat_order_item`;
    TRUNCATE `sales_flat_order_payment`;
    TRUNCATE `sales_flat_order_status_history`;
    TRUNCATE `sales_flat_quote`;
    TRUNCATE `sales_flat_quote_address`;
    TRUNCATE `sales_flat_quote_address_item`;
    TRUNCATE `sales_flat_quote_item`;
    TRUNCATE `sales_flat_quote_item_option`;
    TRUNCATE `sales_flat_quote_payment`;
    TRUNCATE `sales_flat_quote_shipping_rate`;
    TRUNCATE `sales_flat_shipment`;
    TRUNCATE `sales_flat_shipment_comment`;
    TRUNCATE `sales_flat_shipment_grid`;
    TRUNCATE `sales_flat_shipment_item`;
    TRUNCATE `sales_flat_shipment_track`;
    TRUNCATE `sales_invoiced_aggregated`;
    TRUNCATE `sales_invoiced_aggregated_order`;
    TRUNCATE `sales_order_aggregated_created`;
    TRUNCATE `sendfriend_log`;
    TRUNCATE `tag`;
    TRUNCATE `tag_relation`;
    TRUNCATE `tag_summary`;
    TRUNCATE `wishlist`;
    TRUNCATE `log_quote`;
    TRUNCATE `report_event`;
    ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
    ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
    ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
    ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
    ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
    ALTER TABLE `tag` AUTO_INCREMENT=1;
    ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
    ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
    ALTER TABLE `wishlist` AUTO_INCREMENT=1;
    ALTER TABLE `log_quote` AUTO_INCREMENT=1;
    ALTER TABLE `report_event` AUTO_INCREMENT=1;
    SET FOREIGN_KEY_CHECKS=1;

  4. This last one worked for me in Magento 1.4.1.1
    Just had to delete the comments.
    Thanks !! Jordi Bos

  5. oh,it show error on my magento 1.4.1.0.
    here is error:

    Error

    SQL query:

    – RESET dashboard search queries TRUNCATE `catalogsearch_query` ;

    MySQL said: Documentation
    #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘– reset dashboard search queries
    TRUNCATE `catalogsearch_query`’ at line 1

  6. Jordi Bos

    Probably wont work with magento 1.4.1.0

    I tried it with 1.4.1.1 That WORKS FINE!

    @ zdhkw2010 –> check if there is a table called catalogsearch_query
    if there isn’t then remove this line from your query string. Maybe that will help…

    Greets..
    Jordi Bos

  7. Taliya

    Works fine for me on 1.4.1.0, just remove the comment lines starting with “-” before running the query~

    Thanks to Jordi Bos.

  8. Hi, Just like to let you all know that the SQL statements provided by Jordi Bos work like a charm on 1.4.1.1.
    Many thanks!

  9. thanks for the sql script Jordi, it works like a charm…

  10. Vincent

    Anyone got a version for the Enterprise Edition v. 1.7.0.0?

  11. it broke my site, lucky i had backup. It was staging site anyway for just testing. :)

  12. Jordi Bos

    @ Damu:

    what exactly broke your site? which version do you use? I use 1.4.1.1 it works well.

    So maybe you use an older version? I only tested it on 1.4.1.1 but i read posts here that it will also work on 1.4.1.0

    Greets Jordi

  13. vsven

    This works PERFECT for 1.3.2.4!!! At last all my test orders gone :)

    Attention though: all my test clients are gone as well, so if you run this with an already working site, delete the steps that deletes your clients ;)

    S

  14. DO NOT even think of using it for 1.9. Completely brakes everything :)

  15. vsven

    O yeah, small detail, it could be me, but when you’re running some other applications on it, these are not working anymore ;) you have to re-install all!

  16. Rob

    Tried it but it keeps going down the line telling me that tables don’t exist. When they clearly do.

  17. It works perfect on 1.4.1.1

    Many thanks!!

  18. Devon

    For 1.4.1.1 if you have downloadable products don’t forget the queries:
    TRUNCATE `downloadable_link_purchased`;
    TRUNCATE `downloadable_link_purchased_item`;
    ALTER TABLE `downloadable_link_purchased` AUTO_INCREMENT=1;
    ALTER TABLE `downloadable_link_purchased_item` AUTO_INCREMENT=1;

    PS Not sure if the last two are necessary but they don’t hurt!

  19. Miguel

    Thanks a lot Jordi ;)

    Works perfectly on 1.4.1.1

  20. m4t

    I spent my morning looking for single order delete method..

    Starting from Jordi queries, using Magento 1.4.2.0 and after some quick tests, I can say that delete order related row in ‘sales_flat_order’ and ‘sales_flat_quote’ do the trick in (almost) every case; many thanks to key structure of DB!

    Now, my question: are there known issues about this solution?

  21. Pingback: magento database tip: Magento eCommerce: How To Reset All Test Order Information and Set Unique Prefix For Orders, Invoices, Shipments, and Credit Memos @ tipBOX.net

  22. Luc

    Thanks a lot. I used the query in the comment from @Jordi Bos. Next to the tables that are truncated there, I found a view more tables that needs to be truncate:

    TRUNCATE `sales_bestsellers_aggregated_daily`;
    TRUNCATE `sales_bestsellers_aggregated_monthly`;
    TRUNCATE `sales_bestsellers_aggregated_yearly`;
    TRUNCATE `sales_order_tax`;

    @mrt: I did not discover any issues…

  23. Luc

    One more table found. The is’d of the last order, invoice, shipment and credit_memo are stored in the eav_entity_store table.

    According the structure of the database, it looks like this table is used for more types of last id’s. In my test enviroment only the 4 id mentioned above are used.

    I truncated this table too (without any problem).

  24. Many thanks! Exacly what I was searching for!

  25. Does anyone know how to delete only specific orders?

  26. m4t

    You could use jordi/luc queries in a controller.

    Then add this one to select object in order grid.

    It works for me

  27. Thanks for pointing me in the right direction. I’m not so familiar with controllers… can you give me a little more information of how to use the delete queries in a controller and how to “add this one to select object in order grid.”?

  28. m4t

    You should create your own module, with a controller that recall these queries.

    In file IndexController create IndexAction and refill checked order Ids with:

    $this->getRequest()->getPost('order_ids', array())

    Now you can add order Ids to these global queries: in this way you’ll delete only orders checked in order grid.

    Hope it’s clear… english is not my native language!

  29. 
    -- here are the tables modified for 1.5.0.1
    
    SET FOREIGN_KEY_CHECKS=0;
    
    TRUNCATE `sales_flat_order`;
    TRUNCATE `sales_flat_order_address`;
    TRUNCATE `sales_flat_order_grid`;
    TRUNCATE `sales_flat_order_item`;
    TRUNCATE `sales_flat_order_status_history`;
    TRUNCATE `sales_flat_quote`;
    TRUNCATE `sales_flat_quote_address`;
    TRUNCATE `sales_flat_quote_address_item`;
    TRUNCATE `sales_flat_quote_item`;
    TRUNCATE `sales_flat_quote_item_option`;
    TRUNCATE `sales_flat_order_payment`;
    TRUNCATE `sales_flat_quote_payment`;
    TRUNCATE `sales_flat_shipment`;
    TRUNCATE `sales_flat_shipment_item`;
    TRUNCATE `sales_flat_shipment_grid`;
    TRUNCATE `sales_flat_invoice`;
    TRUNCATE `sales_flat_invoice_grid`;
    TRUNCATE `sales_flat_invoice_item`;
    TRUNCATE `sendfriend_log`;
    TRUNCATE `tag`;
    TRUNCATE `tag_relation`;
    TRUNCATE `tag_summary`;
    TRUNCATE `wishlist`;
    TRUNCATE `log_quote`;
    TRUNCATE `report_event`;
    
    ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
    ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
    ALTER TABLE `tag` AUTO_INCREMENT=1;
    ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
    ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
    ALTER TABLE `wishlist` AUTO_INCREMENT=1;
    ALTER TABLE `log_quote` AUTO_INCREMENT=1;
    ALTER TABLE `report_event` AUTO_INCREMENT=1;
    
    -- lets reset customers
    TRUNCATE `customer_address_entity`;
    TRUNCATE `customer_address_entity_datetime`;
    TRUNCATE `customer_address_entity_decimal`;
    TRUNCATE `customer_address_entity_int`;
    TRUNCATE `customer_address_entity_text`;
    TRUNCATE `customer_address_entity_varchar`;
    TRUNCATE `customer_entity`;
    TRUNCATE `customer_entity_datetime`;
    TRUNCATE `customer_entity_decimal`;
    TRUNCATE `customer_entity_int`;
    TRUNCATE `customer_entity_text`;
    TRUNCATE `customer_entity_varchar`;
    TRUNCATE `log_customer`;
    TRUNCATE `log_visitor`;
    TRUNCATE `log_visitor_info`;
    
    ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
    ALTER TABLE `log_customer` AUTO_INCREMENT=1;
    ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
    ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
    
    -- Now, lets Reset all ID counters
    TRUNCATE `eav_entity_store`;
    ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
    
    SET FOREIGN_KEY_CHECKS=1;
    
  30. Thanks Christchurch Web Design for the 1.5.0.1 update of the code!

  31. Genius Christchurch Web Design, code update for 1.5.0.1 works a treat.

  32. Rachel Evans

    Since Magento change the schema more frequently then there are seasons in a year, I gave up trying to understand how to clean the database. I am contacting the guys of http://www.asulpunto.com and ask them to do the clean up themselves for me. They do not charge a lot and keep backups of the original database too.

  33. It’s looking for ‘sales_order’ which doesn’t exist after 1.4.1.0 version? Where is it?

  34. Mark

    The script worked like a charm but it left the return invoices untouched and when I try top open those it results in a long list of errors (since it cannot find the originating order data).

  35. Mark

    managed to rid the credit invoices by adding the following lines:

    TRUNCATE `sales_flat_creditmemo`;
    TRUNCATE `sales_flat_creditmemo_comment`;
    TRUNCATE `sales_flat_creditmemo_grid`;
    TRUNCATE `sales_flat_creditmemo_item`;
    
    ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
    
  36. Hey Inchoo,
    We ran this query and we are having some very strange behavior attached to the first customer to place an order in our store.

    Dashboard shows Brandon Bannerman:
    Number of Orders: 2597
    Average Order Amount: $22.25
    Total Order Amount: $57,774.49

    Click on his name from the customer tab on the dash board and it opens the screen to create a new customer.

    When you search for him he only has four orders associated with his name:
    April 27th – Grand Total $30.59 (Order #1)
    May 15th – Grand Total $32.59
    May 21st – Grand Total $35.78
    May 30th – Grand Total $50.00

    Magento will not create an account for him. He has tried 3-4 times and then when he goes back to log in Magento reports there is no user associated with that email address.

    And when you search customers on the admin side there is no one with his name or email address.

    Do you think it has anything to do with the query?

  37. Thanks for the query. My test site is getting filled with hundreds of test orders and it’s so annoying!

    I’ll be running this script and hopefully, no more annoying test orders and a faster site :)

  38. @Cherie
    this is a bug in magento. We have the same issue and we found that on the dashbord magento stores all guest order under one customer (guest or not). Couse magento can not find information about this customer he send you to “Create Customer” Page. Don’t worry this has nothing to do with the query

  39. Why are you disabeling the foreign keys? If they are you, you only have to TRUNCATE sales_order, to delete all Invoices , order, creditmemo, shipments tables.
    Be carefully, it is very important to TRUNCATE the sales_order_tax table. If you don’t truncate this table and you reset the AUTO_INCREMENT and create an new order, the old tax entries will be assigned to the new order.
    In think there is a missing foreign key constraint on sales_order_tax table, because there is only a foreign key to sales_order.
    You can delete this stuff, by magento model too.
    If you want to delete all customers with an action, call

    Mage::getModel('customer/customer')->getCollection()->delete()

    If you want to delete all orders,invoices, and so on call:

    foreach(Mage::getModel('sales/order')->getCollection() as $order)
    { $order->delete()}

    This code can beused for backend actions.

  40. Hi,

    Did anyone found a way to delete best seller module statistics on the dashboard for 1.5.0.1 ?
    That would be very helpful,

    Many thanks.

  41. Pingback: Deleting Orders in Magento – Extension Roundup | www.ecommerceoffice.com

  42. Robbie

    @Jordi Bos thanks this solution works for 1.4.2.0 also.

  43. Ian

    Something like this seemed to work for me.

    $order = Mage::getModel('sales/order')->loadByIncrementId(100001436);
    $order->delete();
    
  44. Pascal

    This doesn’t work on Magento Version 1.5.1.0. Use this script http://www.exanto.de/magento-testbestellungen-loschen.html instead.

  45. James

    What about the sales_tax_item table? I have received duplicate key errors if I don’t remove all items from this table too.

  46. Worked for me.. thank youu :)

  47. Yup, these is a very helpful script.

    There is also a query you can use directly to the MySQL database.

    Take a look here

    http://wabism.com/magento-clear-all-orders-and-customers/

  48. Thanks

    AMAZING! Great script worked!

  49. Great post and great script. This was tremendously helpful. The only thing I thing is missing would be a way to start the order/invoice numbers from 0 again. I did this through phpMyAdmin by running:

    TRUNCATE `eav_entity_store`;
    ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

    I hope this helps anyone having the same issue. Thanks again!

  50. Great post and great script. This was tremendously helpful. The only action missing is starting the order/invoice numbers from 0 again. I did this through phpMyAdmin by running:

    TRUNCATE `eav_entity_store`;
    ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

    I hope this helps anyone having the same issue. Thanks again!

1 2

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top