how can I delete test order from magento





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







33















I have made a website in magento. Now it is live and I want to delete the all test order. I know there are some table in all these order are stored. but I don't know the name of those table. If some body has any script which can delete the all the order data.



Please give me or please mention the name of all the tables which stores the order information










share|improve this question

























  • blog.magentomagik.com/…

    – haha
    Dec 24 '10 at 15:04











  • New link: blog.magikcommerce.com/…

    – Simon
    Nov 15 '12 at 8:26











  • You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

    – Sarfaraz bheda
    Aug 20 '16 at 13:16


















33















I have made a website in magento. Now it is live and I want to delete the all test order. I know there are some table in all these order are stored. but I don't know the name of those table. If some body has any script which can delete the all the order data.



Please give me or please mention the name of all the tables which stores the order information










share|improve this question

























  • blog.magentomagik.com/…

    – haha
    Dec 24 '10 at 15:04











  • New link: blog.magikcommerce.com/…

    – Simon
    Nov 15 '12 at 8:26











  • You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

    – Sarfaraz bheda
    Aug 20 '16 at 13:16














33












33








33


13






I have made a website in magento. Now it is live and I want to delete the all test order. I know there are some table in all these order are stored. but I don't know the name of those table. If some body has any script which can delete the all the order data.



Please give me or please mention the name of all the tables which stores the order information










share|improve this question
















I have made a website in magento. Now it is live and I want to delete the all test order. I know there are some table in all these order are stored. but I don't know the name of those table. If some body has any script which can delete the all the order data.



Please give me or please mention the name of all the tables which stores the order information







php magento






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '17 at 17:13









Kara

4,033104353




4,033104353










asked Dec 24 '10 at 14:54









mjdevlopermjdevloper

79362660




79362660













  • blog.magentomagik.com/…

    – haha
    Dec 24 '10 at 15:04











  • New link: blog.magikcommerce.com/…

    – Simon
    Nov 15 '12 at 8:26











  • You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

    – Sarfaraz bheda
    Aug 20 '16 at 13:16



















  • blog.magentomagik.com/…

    – haha
    Dec 24 '10 at 15:04











  • New link: blog.magikcommerce.com/…

    – Simon
    Nov 15 '12 at 8:26











  • You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

    – Sarfaraz bheda
    Aug 20 '16 at 13:16

















blog.magentomagik.com/…

– haha
Dec 24 '10 at 15:04





blog.magentomagik.com/…

– haha
Dec 24 '10 at 15:04













New link: blog.magikcommerce.com/…

– Simon
Nov 15 '12 at 8:26





New link: blog.magikcommerce.com/…

– Simon
Nov 15 '12 at 8:26













You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

– Sarfaraz bheda
Aug 20 '16 at 13:16





You can also use this extension: magentocommerce.com/magento-connect/orders-eraser.html

– Sarfaraz bheda
Aug 20 '16 at 13:16












10 Answers
10






active

oldest

votes


















66















  1. Go to admin>sales>orders

  2. Write down your test orders incremental ids, for example
    100000001,100000002,100000003,100000111,100000112,100000199

  3. now create a php file in magento root directory and name it: remove_test_orders.php


  4. Paste the code below:



    require 'app/Mage.php';
    Mage::app('admin')->setUseSessionInUrl(false);
    //replace your own orders numbers here:
    $test_order_ids=array(
    '100000001',
    '100000002',
    '100000003',
    '100000111',
    '100000112',
    '100000199',
    );
    foreach($test_order_ids as $id){
    try{
    Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
    echo "order #".$id." is removed".PHP_EOL;
    }catch(Exception $e){
    echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
    }
    }
    echo "complete.";



  5. Now go to command line and run:



    php remove_test_orders.php



  6. At the end, delete remove_test_orders.php.







share|improve this answer





















  • 1





    Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

    – ravisoni
    Mar 3 '13 at 14:28






  • 1





    hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

    – murali krishna
    Mar 11 '13 at 14:03






  • 1





    I've reindexed my data and am having the same problem as muralikalpana

    – MrJellyhands
    Jan 14 '14 at 17:55






  • 1





    I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

    – jtate
    Apr 1 '15 at 18:25






  • 1





    I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

    – useless
    Jun 1 '15 at 16:40





















14














The above answer is too old and there is drawback of this answer that it doesn't empty payment tables so there is a chance of legacy.
you can use below code it will remove payment information also.



SET FOREIGN_KEY_CHECKS=0;
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;





share|improve this answer



















  • 5





    This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

    – pspahn
    May 27 '15 at 16:14



















8














Take a look at How to delete orders from Magento



<?php
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('default');
Mage::register('isSecureArea', 1);
//until here you gained access to the Magento models. The rest is custom code

$orderId = 156;//put here the id of the order you want to delete. THE ONE FROM THE DATABASE NOT THE INCREMENT_ID

$order = Mage::getModel('sales/order')->load($orderId);

$invoices = $order->getInvoiceCollection();
foreach ($invoices as $invoice){
$invoice->delete();
}

$creditnotes = $order->getCreditmemosCollection();
foreach ($creditnotes as $creditnote){
$creditnote->delete();
}

$shipments = $order->getShipmentsCollection();
foreach ($shipments as $shipment){
$shipment->delete();
}

$order->delete();
?>





share|improve this answer





















  • 1





    I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

    – Kingsley
    May 26 '15 at 9:45











  • And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

    – JPMC
    Jun 3 '15 at 13:35











  • Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

    – ahnbizcad
    Nov 1 '17 at 23:18



















4














I setup a repository for maintaining simple SQL scripts to run before launching a new Magento site. So far they can help:




  1. empty test data from Mage; orders, customers, reports, logs etc.

  2. empty test data from various extensions

  3. set desired IDs for next order, invoice, shipment and creditmemos


https://github.com/ccondrup/mage-reset
Help improve them!






share|improve this answer































    3














    I created an open source commandline tool



    you can use it like this:



    #delete order by increment id
    php -f shell/delete-order.php -- --increment-id 100000001

    #test delete order by increment id (wont actually delete it)
    php -f shell/delete-order.php -- --dry-run --order-id 32


    https://github.com/mauricioprado00/magento-delete-order/releases






    share|improve this answer
























    • Thanks, this was handy :)

      – grok_in_full
      Jan 15 '18 at 4:16



















    2














    Almost all the previous answers have problem with Foreign key Constraint or wrong table names. I was able to achieve the deletion on a Magento v 1.9.1.0 CE using the SQL below, I modified the SQL given in previous answers:



        SET FOREIGN_KEY_CHECKS=0;
    TRUNCATE `mg_sales_flat_creditmemo`;
    TRUNCATE `mg_sales_flat_creditmemo_comment`;
    TRUNCATE `mg_sales_flat_creditmemo_grid`;
    TRUNCATE `mg_sales_flat_creditmemo_item`;
    TRUNCATE `mg_sales_flat_invoice`;
    TRUNCATE `mg_sales_flat_invoice_comment`;
    TRUNCATE `mg_sales_flat_invoice_grid`;
    TRUNCATE `mg_sales_flat_invoice_item`;
    TRUNCATE `mg_sales_flat_order`;
    TRUNCATE `mg_sales_flat_order_address`;
    TRUNCATE `mg_sales_flat_order_grid`;
    TRUNCATE `mg_sales_flat_order_item`;
    TRUNCATE `mg_sales_flat_order_payment`;
    TRUNCATE `mg_sales_flat_order_status_history`;
    TRUNCATE `mg_sales_flat_quote`;
    TRUNCATE `mg_sales_flat_quote_address`;
    TRUNCATE `mg_sales_flat_quote_address_item`;
    TRUNCATE `mg_sales_flat_quote_item`;
    TRUNCATE `mg_sales_flat_quote_item_option`;
    TRUNCATE `mg_sales_flat_quote_payment`;
    TRUNCATE `mg_sales_flat_quote_shipping_rate`;
    TRUNCATE `mg_sales_flat_shipment`;
    TRUNCATE `mg_sales_flat_shipment_comment`;
    TRUNCATE `mg_sales_flat_shipment_grid`;
    TRUNCATE `mg_sales_flat_shipment_item`;
    TRUNCATE `mg_sales_flat_shipment_track`;
    TRUNCATE `mg_sales_invoiced_aggregated`;
    TRUNCATE `mg_sales_invoiced_aggregated_order`;
    TRUNCATE `mg_sales_order_aggregated_created`;
    TRUNCATE `mg_sendfriend_log`;
    TRUNCATE `mg_tag`;
    TRUNCATE `mg_tag_relation`;
    TRUNCATE `mg_tag_summary`;
    TRUNCATE `mg_wishlist`;
    TRUNCATE `mg_log_quote`;
    TRUNCATE `mg_report_event`;
    ALTER TABLE `mg_sales_flat_creditmemo` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_invoice` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_invoice_comment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_invoice_grid` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_invoice_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order_address` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order_grid` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order_payment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_order_status_history` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_address` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_address_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_item_option` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_payment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_shipment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_shipment_comment` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_shipment_grid` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_shipment_item` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_flat_shipment_track` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_invoiced_aggregated` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sales_order_aggregated_created` AUTO_INCREMENT=1;
    ALTER TABLE `mg_sendfriend_log` AUTO_INCREMENT=1;
    ALTER TABLE `mg_tag` AUTO_INCREMENT=1;
    ALTER TABLE `mg_tag_relation` AUTO_INCREMENT=1;
    ALTER TABLE `mg_tag_summary` AUTO_INCREMENT=1;
    ALTER TABLE `mg_wishlist` AUTO_INCREMENT=1;
    ALTER TABLE `mg_log_quote` AUTO_INCREMENT=1;
    ALTER TABLE `mg_report_event` AUTO_INCREMENT=1;

    SET FOREIGN_KEY_CHECKS=1;


    Remember to change mg_ to your table prefix.






    share|improve this answer



















    • 1





      Veeeery useful dude. Thanks.

      – EliaszKubala
      Aug 4 '15 at 7:30



















    1














    Create a file in the root directory and paste the following code.
    It will remove all the orders from admin grid!

    <?php

    /**
    * @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...');

    ?>





    share|improve this answer































      0














      Try this one from Inchoo:



      Delete test orders in Magento






      share|improve this answer
























      • I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

        – Buttle Butkus
        Mar 26 '14 at 19:05



















      0














      With this extension, not only it will delete the order(s), invoice(s), shipment(s), credit memo(s), RMA(s), but also it will revert back all the information such as collected tax, deleted products back to inventory and reset Increment IDs.



      If you make a mistake when creating the order/invoice/shipment/credit memo/RMA and want to delete it, then this extension can do very well.



      There is a test site where you can try it first and see if it works for you or not.



      http://www.magentocommerce.com/magento-connect/ultimate-delete-order.html






      share|improve this answer

































        0














        Simply got your database phpMyadmin and then open the table sales_flat_order and then simply remove tha data from this tabel and your test orders will be cleared. No need of any code or commands. cool.






        share|improve this answer






















          protected by Community Jan 4 '13 at 2:19



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          10 Answers
          10






          active

          oldest

          votes








          10 Answers
          10






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          66















          1. Go to admin>sales>orders

          2. Write down your test orders incremental ids, for example
            100000001,100000002,100000003,100000111,100000112,100000199

          3. now create a php file in magento root directory and name it: remove_test_orders.php


          4. Paste the code below:



            require 'app/Mage.php';
            Mage::app('admin')->setUseSessionInUrl(false);
            //replace your own orders numbers here:
            $test_order_ids=array(
            '100000001',
            '100000002',
            '100000003',
            '100000111',
            '100000112',
            '100000199',
            );
            foreach($test_order_ids as $id){
            try{
            Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
            echo "order #".$id." is removed".PHP_EOL;
            }catch(Exception $e){
            echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
            }
            }
            echo "complete.";



          5. Now go to command line and run:



            php remove_test_orders.php



          6. At the end, delete remove_test_orders.php.







          share|improve this answer





















          • 1





            Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

            – ravisoni
            Mar 3 '13 at 14:28






          • 1





            hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

            – murali krishna
            Mar 11 '13 at 14:03






          • 1





            I've reindexed my data and am having the same problem as muralikalpana

            – MrJellyhands
            Jan 14 '14 at 17:55






          • 1





            I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

            – jtate
            Apr 1 '15 at 18:25






          • 1





            I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

            – useless
            Jun 1 '15 at 16:40


















          66















          1. Go to admin>sales>orders

          2. Write down your test orders incremental ids, for example
            100000001,100000002,100000003,100000111,100000112,100000199

          3. now create a php file in magento root directory and name it: remove_test_orders.php


          4. Paste the code below:



            require 'app/Mage.php';
            Mage::app('admin')->setUseSessionInUrl(false);
            //replace your own orders numbers here:
            $test_order_ids=array(
            '100000001',
            '100000002',
            '100000003',
            '100000111',
            '100000112',
            '100000199',
            );
            foreach($test_order_ids as $id){
            try{
            Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
            echo "order #".$id." is removed".PHP_EOL;
            }catch(Exception $e){
            echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
            }
            }
            echo "complete.";



          5. Now go to command line and run:



            php remove_test_orders.php



          6. At the end, delete remove_test_orders.php.







          share|improve this answer





















          • 1





            Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

            – ravisoni
            Mar 3 '13 at 14:28






          • 1





            hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

            – murali krishna
            Mar 11 '13 at 14:03






          • 1





            I've reindexed my data and am having the same problem as muralikalpana

            – MrJellyhands
            Jan 14 '14 at 17:55






          • 1





            I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

            – jtate
            Apr 1 '15 at 18:25






          • 1





            I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

            – useless
            Jun 1 '15 at 16:40
















          66












          66








          66








          1. Go to admin>sales>orders

          2. Write down your test orders incremental ids, for example
            100000001,100000002,100000003,100000111,100000112,100000199

          3. now create a php file in magento root directory and name it: remove_test_orders.php


          4. Paste the code below:



            require 'app/Mage.php';
            Mage::app('admin')->setUseSessionInUrl(false);
            //replace your own orders numbers here:
            $test_order_ids=array(
            '100000001',
            '100000002',
            '100000003',
            '100000111',
            '100000112',
            '100000199',
            );
            foreach($test_order_ids as $id){
            try{
            Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
            echo "order #".$id." is removed".PHP_EOL;
            }catch(Exception $e){
            echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
            }
            }
            echo "complete.";



          5. Now go to command line and run:



            php remove_test_orders.php



          6. At the end, delete remove_test_orders.php.







          share|improve this answer
















          1. Go to admin>sales>orders

          2. Write down your test orders incremental ids, for example
            100000001,100000002,100000003,100000111,100000112,100000199

          3. now create a php file in magento root directory and name it: remove_test_orders.php


          4. Paste the code below:



            require 'app/Mage.php';
            Mage::app('admin')->setUseSessionInUrl(false);
            //replace your own orders numbers here:
            $test_order_ids=array(
            '100000001',
            '100000002',
            '100000003',
            '100000111',
            '100000112',
            '100000199',
            );
            foreach($test_order_ids as $id){
            try{
            Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
            echo "order #".$id." is removed".PHP_EOL;
            }catch(Exception $e){
            echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
            }
            }
            echo "complete.";



          5. Now go to command line and run:



            php remove_test_orders.php



          6. At the end, delete remove_test_orders.php.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 2 '17 at 10:34









          R Hisgen

          53




          53










          answered Dec 25 '10 at 23:44









          cubnycubny

          1,9141612




          1,9141612








          • 1





            Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

            – ravisoni
            Mar 3 '13 at 14:28






          • 1





            hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

            – murali krishna
            Mar 11 '13 at 14:03






          • 1





            I've reindexed my data and am having the same problem as muralikalpana

            – MrJellyhands
            Jan 14 '14 at 17:55






          • 1





            I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

            – jtate
            Apr 1 '15 at 18:25






          • 1





            I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

            – useless
            Jun 1 '15 at 16:40
















          • 1





            Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

            – ravisoni
            Mar 3 '13 at 14:28






          • 1





            hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

            – murali krishna
            Mar 11 '13 at 14:03






          • 1





            I've reindexed my data and am having the same problem as muralikalpana

            – MrJellyhands
            Jan 14 '14 at 17:55






          • 1





            I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

            – jtate
            Apr 1 '15 at 18:25






          • 1





            I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

            – useless
            Jun 1 '15 at 16:40










          1




          1





          Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

          – ravisoni
          Mar 3 '13 at 14:28





          Hey.. is there any code that delete the orders and also re-level the inventory,means also add the quantity back to products

          – ravisoni
          Mar 3 '13 at 14:28




          1




          1





          hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

          – murali krishna
          Mar 11 '13 at 14:03





          hey i used the above code. but still order is showing in my orders grid. when ever i click on order it is showing "order is no longer exists". i thing something went wrong.

          – murali krishna
          Mar 11 '13 at 14:03




          1




          1





          I've reindexed my data and am having the same problem as muralikalpana

          – MrJellyhands
          Jan 14 '14 at 17:55





          I've reindexed my data and am having the same problem as muralikalpana

          – MrJellyhands
          Jan 14 '14 at 17:55




          1




          1





          I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

          – jtate
          Apr 1 '15 at 18:25





          I can confirm that this works on Magento ver. 1.9.0.1. It seems to be deleting all relevant data tied to the order as well, like invoices, transactions, etc.

          – jtate
          Apr 1 '15 at 18:25




          1




          1





          I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

          – useless
          Jun 1 '15 at 16:40







          I created a commanline tool, if anyone interested: github.com/mauricioprado00/magento-delete-order/releases

          – useless
          Jun 1 '15 at 16:40















          14














          The above answer is too old and there is drawback of this answer that it doesn't empty payment tables so there is a chance of legacy.
          you can use below code it will remove payment information also.



          SET FOREIGN_KEY_CHECKS=0;
          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;





          share|improve this answer



















          • 5





            This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

            – pspahn
            May 27 '15 at 16:14
















          14














          The above answer is too old and there is drawback of this answer that it doesn't empty payment tables so there is a chance of legacy.
          you can use below code it will remove payment information also.



          SET FOREIGN_KEY_CHECKS=0;
          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;





          share|improve this answer



















          • 5





            This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

            – pspahn
            May 27 '15 at 16:14














          14












          14








          14







          The above answer is too old and there is drawback of this answer that it doesn't empty payment tables so there is a chance of legacy.
          you can use below code it will remove payment information also.



          SET FOREIGN_KEY_CHECKS=0;
          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;





          share|improve this answer













          The above answer is too old and there is drawback of this answer that it doesn't empty payment tables so there is a chance of legacy.
          you can use below code it will remove payment information also.



          SET FOREIGN_KEY_CHECKS=0;
          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;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 11 '14 at 13:14









          urfusionurfusion

          4,29343571




          4,29343571








          • 5





            This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

            – pspahn
            May 27 '15 at 16:14














          • 5





            This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

            – pspahn
            May 27 '15 at 16:14








          5




          5





          This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

          – pspahn
          May 27 '15 at 16:14





          This is going to delete all orders, not just test orders as the question asks. Be wary before you run this.

          – pspahn
          May 27 '15 at 16:14











          8














          Take a look at How to delete orders from Magento



          <?php
          $mageFilename = 'app/Mage.php';
          require_once $mageFilename;
          Varien_Profiler::enable();
          Mage::setIsDeveloperMode(true);
          ini_set('display_errors', 1);
          umask(0);
          Mage::app('default');
          Mage::register('isSecureArea', 1);
          //until here you gained access to the Magento models. The rest is custom code

          $orderId = 156;//put here the id of the order you want to delete. THE ONE FROM THE DATABASE NOT THE INCREMENT_ID

          $order = Mage::getModel('sales/order')->load($orderId);

          $invoices = $order->getInvoiceCollection();
          foreach ($invoices as $invoice){
          $invoice->delete();
          }

          $creditnotes = $order->getCreditmemosCollection();
          foreach ($creditnotes as $creditnote){
          $creditnote->delete();
          }

          $shipments = $order->getShipmentsCollection();
          foreach ($shipments as $shipment){
          $shipment->delete();
          }

          $order->delete();
          ?>





          share|improve this answer





















          • 1





            I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

            – Kingsley
            May 26 '15 at 9:45











          • And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

            – JPMC
            Jun 3 '15 at 13:35











          • Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

            – ahnbizcad
            Nov 1 '17 at 23:18
















          8














          Take a look at How to delete orders from Magento



          <?php
          $mageFilename = 'app/Mage.php';
          require_once $mageFilename;
          Varien_Profiler::enable();
          Mage::setIsDeveloperMode(true);
          ini_set('display_errors', 1);
          umask(0);
          Mage::app('default');
          Mage::register('isSecureArea', 1);
          //until here you gained access to the Magento models. The rest is custom code

          $orderId = 156;//put here the id of the order you want to delete. THE ONE FROM THE DATABASE NOT THE INCREMENT_ID

          $order = Mage::getModel('sales/order')->load($orderId);

          $invoices = $order->getInvoiceCollection();
          foreach ($invoices as $invoice){
          $invoice->delete();
          }

          $creditnotes = $order->getCreditmemosCollection();
          foreach ($creditnotes as $creditnote){
          $creditnote->delete();
          }

          $shipments = $order->getShipmentsCollection();
          foreach ($shipments as $shipment){
          $shipment->delete();
          }

          $order->delete();
          ?>





          share|improve this answer





















          • 1





            I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

            – Kingsley
            May 26 '15 at 9:45











          • And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

            – JPMC
            Jun 3 '15 at 13:35











          • Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

            – ahnbizcad
            Nov 1 '17 at 23:18














          8












          8








          8







          Take a look at How to delete orders from Magento



          <?php
          $mageFilename = 'app/Mage.php';
          require_once $mageFilename;
          Varien_Profiler::enable();
          Mage::setIsDeveloperMode(true);
          ini_set('display_errors', 1);
          umask(0);
          Mage::app('default');
          Mage::register('isSecureArea', 1);
          //until here you gained access to the Magento models. The rest is custom code

          $orderId = 156;//put here the id of the order you want to delete. THE ONE FROM THE DATABASE NOT THE INCREMENT_ID

          $order = Mage::getModel('sales/order')->load($orderId);

          $invoices = $order->getInvoiceCollection();
          foreach ($invoices as $invoice){
          $invoice->delete();
          }

          $creditnotes = $order->getCreditmemosCollection();
          foreach ($creditnotes as $creditnote){
          $creditnote->delete();
          }

          $shipments = $order->getShipmentsCollection();
          foreach ($shipments as $shipment){
          $shipment->delete();
          }

          $order->delete();
          ?>





          share|improve this answer















          Take a look at How to delete orders from Magento



          <?php
          $mageFilename = 'app/Mage.php';
          require_once $mageFilename;
          Varien_Profiler::enable();
          Mage::setIsDeveloperMode(true);
          ini_set('display_errors', 1);
          umask(0);
          Mage::app('default');
          Mage::register('isSecureArea', 1);
          //until here you gained access to the Magento models. The rest is custom code

          $orderId = 156;//put here the id of the order you want to delete. THE ONE FROM THE DATABASE NOT THE INCREMENT_ID

          $order = Mage::getModel('sales/order')->load($orderId);

          $invoices = $order->getInvoiceCollection();
          foreach ($invoices as $invoice){
          $invoice->delete();
          }

          $creditnotes = $order->getCreditmemosCollection();
          foreach ($creditnotes as $creditnote){
          $creditnote->delete();
          }

          $shipments = $order->getShipmentsCollection();
          foreach ($shipments as $shipment){
          $shipment->delete();
          }

          $order->delete();
          ?>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 25 '14 at 23:40

























          answered Aug 15 '14 at 16:21









          Renon StewartRenon Stewart

          16.8k24059




          16.8k24059








          • 1





            I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

            – Kingsley
            May 26 '15 at 9:45











          • And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

            – JPMC
            Jun 3 '15 at 13:35











          • Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

            – ahnbizcad
            Nov 1 '17 at 23:18














          • 1





            I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

            – Kingsley
            May 26 '15 at 9:45











          • And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

            – JPMC
            Jun 3 '15 at 13:35











          • Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

            – ahnbizcad
            Nov 1 '17 at 23:18








          1




          1





          I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

          – Kingsley
          May 26 '15 at 9:45





          I prefer this method. As It also clears the invoices, credit notes, and shipments. Whereas I'm not sure if the accepted answer does. +1

          – Kingsley
          May 26 '15 at 9:45













          And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

          – JPMC
          Jun 3 '15 at 13:35





          And if you have an extension that overrides the normal orders model, you just load the extended orders collection instead of sales/order and it deletes thoughts just fine too! (Looking at Sweettooth rewards)

          – JPMC
          Jun 3 '15 at 13:35













          Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

          – ahnbizcad
          Nov 1 '17 at 23:18





          Use $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if you want to load by increment id.

          – ahnbizcad
          Nov 1 '17 at 23:18











          4














          I setup a repository for maintaining simple SQL scripts to run before launching a new Magento site. So far they can help:




          1. empty test data from Mage; orders, customers, reports, logs etc.

          2. empty test data from various extensions

          3. set desired IDs for next order, invoice, shipment and creditmemos


          https://github.com/ccondrup/mage-reset
          Help improve them!






          share|improve this answer




























            4














            I setup a repository for maintaining simple SQL scripts to run before launching a new Magento site. So far they can help:




            1. empty test data from Mage; orders, customers, reports, logs etc.

            2. empty test data from various extensions

            3. set desired IDs for next order, invoice, shipment and creditmemos


            https://github.com/ccondrup/mage-reset
            Help improve them!






            share|improve this answer


























              4












              4








              4







              I setup a repository for maintaining simple SQL scripts to run before launching a new Magento site. So far they can help:




              1. empty test data from Mage; orders, customers, reports, logs etc.

              2. empty test data from various extensions

              3. set desired IDs for next order, invoice, shipment and creditmemos


              https://github.com/ccondrup/mage-reset
              Help improve them!






              share|improve this answer













              I setup a repository for maintaining simple SQL scripts to run before launching a new Magento site. So far they can help:




              1. empty test data from Mage; orders, customers, reports, logs etc.

              2. empty test data from various extensions

              3. set desired IDs for next order, invoice, shipment and creditmemos


              https://github.com/ccondrup/mage-reset
              Help improve them!







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 5 '13 at 0:57









              ccondrupccondrup

              394517




              394517























                  3














                  I created an open source commandline tool



                  you can use it like this:



                  #delete order by increment id
                  php -f shell/delete-order.php -- --increment-id 100000001

                  #test delete order by increment id (wont actually delete it)
                  php -f shell/delete-order.php -- --dry-run --order-id 32


                  https://github.com/mauricioprado00/magento-delete-order/releases






                  share|improve this answer
























                  • Thanks, this was handy :)

                    – grok_in_full
                    Jan 15 '18 at 4:16
















                  3














                  I created an open source commandline tool



                  you can use it like this:



                  #delete order by increment id
                  php -f shell/delete-order.php -- --increment-id 100000001

                  #test delete order by increment id (wont actually delete it)
                  php -f shell/delete-order.php -- --dry-run --order-id 32


                  https://github.com/mauricioprado00/magento-delete-order/releases






                  share|improve this answer
























                  • Thanks, this was handy :)

                    – grok_in_full
                    Jan 15 '18 at 4:16














                  3












                  3








                  3







                  I created an open source commandline tool



                  you can use it like this:



                  #delete order by increment id
                  php -f shell/delete-order.php -- --increment-id 100000001

                  #test delete order by increment id (wont actually delete it)
                  php -f shell/delete-order.php -- --dry-run --order-id 32


                  https://github.com/mauricioprado00/magento-delete-order/releases






                  share|improve this answer













                  I created an open source commandline tool



                  you can use it like this:



                  #delete order by increment id
                  php -f shell/delete-order.php -- --increment-id 100000001

                  #test delete order by increment id (wont actually delete it)
                  php -f shell/delete-order.php -- --dry-run --order-id 32


                  https://github.com/mauricioprado00/magento-delete-order/releases







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 1 '15 at 16:42









                  uselessuseless

                  1,6001315




                  1,6001315













                  • Thanks, this was handy :)

                    – grok_in_full
                    Jan 15 '18 at 4:16



















                  • Thanks, this was handy :)

                    – grok_in_full
                    Jan 15 '18 at 4:16

















                  Thanks, this was handy :)

                  – grok_in_full
                  Jan 15 '18 at 4:16





                  Thanks, this was handy :)

                  – grok_in_full
                  Jan 15 '18 at 4:16











                  2














                  Almost all the previous answers have problem with Foreign key Constraint or wrong table names. I was able to achieve the deletion on a Magento v 1.9.1.0 CE using the SQL below, I modified the SQL given in previous answers:



                      SET FOREIGN_KEY_CHECKS=0;
                  TRUNCATE `mg_sales_flat_creditmemo`;
                  TRUNCATE `mg_sales_flat_creditmemo_comment`;
                  TRUNCATE `mg_sales_flat_creditmemo_grid`;
                  TRUNCATE `mg_sales_flat_creditmemo_item`;
                  TRUNCATE `mg_sales_flat_invoice`;
                  TRUNCATE `mg_sales_flat_invoice_comment`;
                  TRUNCATE `mg_sales_flat_invoice_grid`;
                  TRUNCATE `mg_sales_flat_invoice_item`;
                  TRUNCATE `mg_sales_flat_order`;
                  TRUNCATE `mg_sales_flat_order_address`;
                  TRUNCATE `mg_sales_flat_order_grid`;
                  TRUNCATE `mg_sales_flat_order_item`;
                  TRUNCATE `mg_sales_flat_order_payment`;
                  TRUNCATE `mg_sales_flat_order_status_history`;
                  TRUNCATE `mg_sales_flat_quote`;
                  TRUNCATE `mg_sales_flat_quote_address`;
                  TRUNCATE `mg_sales_flat_quote_address_item`;
                  TRUNCATE `mg_sales_flat_quote_item`;
                  TRUNCATE `mg_sales_flat_quote_item_option`;
                  TRUNCATE `mg_sales_flat_quote_payment`;
                  TRUNCATE `mg_sales_flat_quote_shipping_rate`;
                  TRUNCATE `mg_sales_flat_shipment`;
                  TRUNCATE `mg_sales_flat_shipment_comment`;
                  TRUNCATE `mg_sales_flat_shipment_grid`;
                  TRUNCATE `mg_sales_flat_shipment_item`;
                  TRUNCATE `mg_sales_flat_shipment_track`;
                  TRUNCATE `mg_sales_invoiced_aggregated`;
                  TRUNCATE `mg_sales_invoiced_aggregated_order`;
                  TRUNCATE `mg_sales_order_aggregated_created`;
                  TRUNCATE `mg_sendfriend_log`;
                  TRUNCATE `mg_tag`;
                  TRUNCATE `mg_tag_relation`;
                  TRUNCATE `mg_tag_summary`;
                  TRUNCATE `mg_wishlist`;
                  TRUNCATE `mg_log_quote`;
                  TRUNCATE `mg_report_event`;
                  ALTER TABLE `mg_sales_flat_creditmemo` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_status_history` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item_option` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_track` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_order_aggregated_created` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sendfriend_log` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_relation` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_summary` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_wishlist` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_log_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_report_event` AUTO_INCREMENT=1;

                  SET FOREIGN_KEY_CHECKS=1;


                  Remember to change mg_ to your table prefix.






                  share|improve this answer



















                  • 1





                    Veeeery useful dude. Thanks.

                    – EliaszKubala
                    Aug 4 '15 at 7:30
















                  2














                  Almost all the previous answers have problem with Foreign key Constraint or wrong table names. I was able to achieve the deletion on a Magento v 1.9.1.0 CE using the SQL below, I modified the SQL given in previous answers:



                      SET FOREIGN_KEY_CHECKS=0;
                  TRUNCATE `mg_sales_flat_creditmemo`;
                  TRUNCATE `mg_sales_flat_creditmemo_comment`;
                  TRUNCATE `mg_sales_flat_creditmemo_grid`;
                  TRUNCATE `mg_sales_flat_creditmemo_item`;
                  TRUNCATE `mg_sales_flat_invoice`;
                  TRUNCATE `mg_sales_flat_invoice_comment`;
                  TRUNCATE `mg_sales_flat_invoice_grid`;
                  TRUNCATE `mg_sales_flat_invoice_item`;
                  TRUNCATE `mg_sales_flat_order`;
                  TRUNCATE `mg_sales_flat_order_address`;
                  TRUNCATE `mg_sales_flat_order_grid`;
                  TRUNCATE `mg_sales_flat_order_item`;
                  TRUNCATE `mg_sales_flat_order_payment`;
                  TRUNCATE `mg_sales_flat_order_status_history`;
                  TRUNCATE `mg_sales_flat_quote`;
                  TRUNCATE `mg_sales_flat_quote_address`;
                  TRUNCATE `mg_sales_flat_quote_address_item`;
                  TRUNCATE `mg_sales_flat_quote_item`;
                  TRUNCATE `mg_sales_flat_quote_item_option`;
                  TRUNCATE `mg_sales_flat_quote_payment`;
                  TRUNCATE `mg_sales_flat_quote_shipping_rate`;
                  TRUNCATE `mg_sales_flat_shipment`;
                  TRUNCATE `mg_sales_flat_shipment_comment`;
                  TRUNCATE `mg_sales_flat_shipment_grid`;
                  TRUNCATE `mg_sales_flat_shipment_item`;
                  TRUNCATE `mg_sales_flat_shipment_track`;
                  TRUNCATE `mg_sales_invoiced_aggregated`;
                  TRUNCATE `mg_sales_invoiced_aggregated_order`;
                  TRUNCATE `mg_sales_order_aggregated_created`;
                  TRUNCATE `mg_sendfriend_log`;
                  TRUNCATE `mg_tag`;
                  TRUNCATE `mg_tag_relation`;
                  TRUNCATE `mg_tag_summary`;
                  TRUNCATE `mg_wishlist`;
                  TRUNCATE `mg_log_quote`;
                  TRUNCATE `mg_report_event`;
                  ALTER TABLE `mg_sales_flat_creditmemo` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_status_history` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item_option` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_track` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_order_aggregated_created` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sendfriend_log` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_relation` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_summary` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_wishlist` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_log_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_report_event` AUTO_INCREMENT=1;

                  SET FOREIGN_KEY_CHECKS=1;


                  Remember to change mg_ to your table prefix.






                  share|improve this answer



















                  • 1





                    Veeeery useful dude. Thanks.

                    – EliaszKubala
                    Aug 4 '15 at 7:30














                  2












                  2








                  2







                  Almost all the previous answers have problem with Foreign key Constraint or wrong table names. I was able to achieve the deletion on a Magento v 1.9.1.0 CE using the SQL below, I modified the SQL given in previous answers:



                      SET FOREIGN_KEY_CHECKS=0;
                  TRUNCATE `mg_sales_flat_creditmemo`;
                  TRUNCATE `mg_sales_flat_creditmemo_comment`;
                  TRUNCATE `mg_sales_flat_creditmemo_grid`;
                  TRUNCATE `mg_sales_flat_creditmemo_item`;
                  TRUNCATE `mg_sales_flat_invoice`;
                  TRUNCATE `mg_sales_flat_invoice_comment`;
                  TRUNCATE `mg_sales_flat_invoice_grid`;
                  TRUNCATE `mg_sales_flat_invoice_item`;
                  TRUNCATE `mg_sales_flat_order`;
                  TRUNCATE `mg_sales_flat_order_address`;
                  TRUNCATE `mg_sales_flat_order_grid`;
                  TRUNCATE `mg_sales_flat_order_item`;
                  TRUNCATE `mg_sales_flat_order_payment`;
                  TRUNCATE `mg_sales_flat_order_status_history`;
                  TRUNCATE `mg_sales_flat_quote`;
                  TRUNCATE `mg_sales_flat_quote_address`;
                  TRUNCATE `mg_sales_flat_quote_address_item`;
                  TRUNCATE `mg_sales_flat_quote_item`;
                  TRUNCATE `mg_sales_flat_quote_item_option`;
                  TRUNCATE `mg_sales_flat_quote_payment`;
                  TRUNCATE `mg_sales_flat_quote_shipping_rate`;
                  TRUNCATE `mg_sales_flat_shipment`;
                  TRUNCATE `mg_sales_flat_shipment_comment`;
                  TRUNCATE `mg_sales_flat_shipment_grid`;
                  TRUNCATE `mg_sales_flat_shipment_item`;
                  TRUNCATE `mg_sales_flat_shipment_track`;
                  TRUNCATE `mg_sales_invoiced_aggregated`;
                  TRUNCATE `mg_sales_invoiced_aggregated_order`;
                  TRUNCATE `mg_sales_order_aggregated_created`;
                  TRUNCATE `mg_sendfriend_log`;
                  TRUNCATE `mg_tag`;
                  TRUNCATE `mg_tag_relation`;
                  TRUNCATE `mg_tag_summary`;
                  TRUNCATE `mg_wishlist`;
                  TRUNCATE `mg_log_quote`;
                  TRUNCATE `mg_report_event`;
                  ALTER TABLE `mg_sales_flat_creditmemo` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_status_history` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item_option` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_track` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_order_aggregated_created` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sendfriend_log` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_relation` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_summary` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_wishlist` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_log_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_report_event` AUTO_INCREMENT=1;

                  SET FOREIGN_KEY_CHECKS=1;


                  Remember to change mg_ to your table prefix.






                  share|improve this answer













                  Almost all the previous answers have problem with Foreign key Constraint or wrong table names. I was able to achieve the deletion on a Magento v 1.9.1.0 CE using the SQL below, I modified the SQL given in previous answers:



                      SET FOREIGN_KEY_CHECKS=0;
                  TRUNCATE `mg_sales_flat_creditmemo`;
                  TRUNCATE `mg_sales_flat_creditmemo_comment`;
                  TRUNCATE `mg_sales_flat_creditmemo_grid`;
                  TRUNCATE `mg_sales_flat_creditmemo_item`;
                  TRUNCATE `mg_sales_flat_invoice`;
                  TRUNCATE `mg_sales_flat_invoice_comment`;
                  TRUNCATE `mg_sales_flat_invoice_grid`;
                  TRUNCATE `mg_sales_flat_invoice_item`;
                  TRUNCATE `mg_sales_flat_order`;
                  TRUNCATE `mg_sales_flat_order_address`;
                  TRUNCATE `mg_sales_flat_order_grid`;
                  TRUNCATE `mg_sales_flat_order_item`;
                  TRUNCATE `mg_sales_flat_order_payment`;
                  TRUNCATE `mg_sales_flat_order_status_history`;
                  TRUNCATE `mg_sales_flat_quote`;
                  TRUNCATE `mg_sales_flat_quote_address`;
                  TRUNCATE `mg_sales_flat_quote_address_item`;
                  TRUNCATE `mg_sales_flat_quote_item`;
                  TRUNCATE `mg_sales_flat_quote_item_option`;
                  TRUNCATE `mg_sales_flat_quote_payment`;
                  TRUNCATE `mg_sales_flat_quote_shipping_rate`;
                  TRUNCATE `mg_sales_flat_shipment`;
                  TRUNCATE `mg_sales_flat_shipment_comment`;
                  TRUNCATE `mg_sales_flat_shipment_grid`;
                  TRUNCATE `mg_sales_flat_shipment_item`;
                  TRUNCATE `mg_sales_flat_shipment_track`;
                  TRUNCATE `mg_sales_invoiced_aggregated`;
                  TRUNCATE `mg_sales_invoiced_aggregated_order`;
                  TRUNCATE `mg_sales_order_aggregated_created`;
                  TRUNCATE `mg_sendfriend_log`;
                  TRUNCATE `mg_tag`;
                  TRUNCATE `mg_tag_relation`;
                  TRUNCATE `mg_tag_summary`;
                  TRUNCATE `mg_wishlist`;
                  TRUNCATE `mg_log_quote`;
                  TRUNCATE `mg_report_event`;
                  ALTER TABLE `mg_sales_flat_creditmemo` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_invoice_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_order_status_history` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_address_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_item_option` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_payment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_comment` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_grid` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_item` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_flat_shipment_track` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sales_order_aggregated_created` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_sendfriend_log` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_relation` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_tag_summary` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_wishlist` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_log_quote` AUTO_INCREMENT=1;
                  ALTER TABLE `mg_report_event` AUTO_INCREMENT=1;

                  SET FOREIGN_KEY_CHECKS=1;


                  Remember to change mg_ to your table prefix.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 24 '14 at 7:52









                  Abubakar Siddiq AngoAbubakar Siddiq Ango

                  12818




                  12818








                  • 1





                    Veeeery useful dude. Thanks.

                    – EliaszKubala
                    Aug 4 '15 at 7:30














                  • 1





                    Veeeery useful dude. Thanks.

                    – EliaszKubala
                    Aug 4 '15 at 7:30








                  1




                  1





                  Veeeery useful dude. Thanks.

                  – EliaszKubala
                  Aug 4 '15 at 7:30





                  Veeeery useful dude. Thanks.

                  – EliaszKubala
                  Aug 4 '15 at 7:30











                  1














                  Create a file in the root directory and paste the following code.
                  It will remove all the orders from admin grid!

                  <?php

                  /**
                  * @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...');

                  ?>





                  share|improve this answer




























                    1














                    Create a file in the root directory and paste the following code.
                    It will remove all the orders from admin grid!

                    <?php

                    /**
                    * @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...');

                    ?>





                    share|improve this answer


























                      1












                      1








                      1







                      Create a file in the root directory and paste the following code.
                      It will remove all the orders from admin grid!

                      <?php

                      /**
                      * @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...');

                      ?>





                      share|improve this answer













                      Create a file in the root directory and paste the following code.
                      It will remove all the orders from admin grid!

                      <?php

                      /**
                      * @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...');

                      ?>






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 19 '15 at 9:29









                      Vivek KhandelwalVivek Khandelwal

                      2009




                      2009























                          0














                          Try this one from Inchoo:



                          Delete test orders in Magento






                          share|improve this answer
























                          • I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                            – Buttle Butkus
                            Mar 26 '14 at 19:05
















                          0














                          Try this one from Inchoo:



                          Delete test orders in Magento






                          share|improve this answer
























                          • I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                            – Buttle Butkus
                            Mar 26 '14 at 19:05














                          0












                          0








                          0







                          Try this one from Inchoo:



                          Delete test orders in Magento






                          share|improve this answer













                          Try this one from Inchoo:



                          Delete test orders in Magento







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 4 '11 at 15:53









                          Richard FeraroRichard Feraro

                          42949




                          42949













                          • I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                            – Buttle Butkus
                            Mar 26 '14 at 19:05



















                          • I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                            – Buttle Butkus
                            Mar 26 '14 at 19:05

















                          I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                          – Buttle Butkus
                          Mar 26 '14 at 19:05





                          I tried to copy/paste into vim and ended up with a bunch of weird characters. The accepted answer worked for me.

                          – Buttle Butkus
                          Mar 26 '14 at 19:05











                          0














                          With this extension, not only it will delete the order(s), invoice(s), shipment(s), credit memo(s), RMA(s), but also it will revert back all the information such as collected tax, deleted products back to inventory and reset Increment IDs.



                          If you make a mistake when creating the order/invoice/shipment/credit memo/RMA and want to delete it, then this extension can do very well.



                          There is a test site where you can try it first and see if it works for you or not.



                          http://www.magentocommerce.com/magento-connect/ultimate-delete-order.html






                          share|improve this answer






























                            0














                            With this extension, not only it will delete the order(s), invoice(s), shipment(s), credit memo(s), RMA(s), but also it will revert back all the information such as collected tax, deleted products back to inventory and reset Increment IDs.



                            If you make a mistake when creating the order/invoice/shipment/credit memo/RMA and want to delete it, then this extension can do very well.



                            There is a test site where you can try it first and see if it works for you or not.



                            http://www.magentocommerce.com/magento-connect/ultimate-delete-order.html






                            share|improve this answer




























                              0












                              0








                              0







                              With this extension, not only it will delete the order(s), invoice(s), shipment(s), credit memo(s), RMA(s), but also it will revert back all the information such as collected tax, deleted products back to inventory and reset Increment IDs.



                              If you make a mistake when creating the order/invoice/shipment/credit memo/RMA and want to delete it, then this extension can do very well.



                              There is a test site where you can try it first and see if it works for you or not.



                              http://www.magentocommerce.com/magento-connect/ultimate-delete-order.html






                              share|improve this answer















                              With this extension, not only it will delete the order(s), invoice(s), shipment(s), credit memo(s), RMA(s), but also it will revert back all the information such as collected tax, deleted products back to inventory and reset Increment IDs.



                              If you make a mistake when creating the order/invoice/shipment/credit memo/RMA and want to delete it, then this extension can do very well.



                              There is a test site where you can try it first and see if it works for you or not.



                              http://www.magentocommerce.com/magento-connect/ultimate-delete-order.html







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Oct 27 '13 at 15:17

























                              answered Oct 25 '13 at 4:09









                              user1801605user1801605

                              112311




                              112311























                                  0














                                  Simply got your database phpMyadmin and then open the table sales_flat_order and then simply remove tha data from this tabel and your test orders will be cleared. No need of any code or commands. cool.






                                  share|improve this answer




























                                    0














                                    Simply got your database phpMyadmin and then open the table sales_flat_order and then simply remove tha data from this tabel and your test orders will be cleared. No need of any code or commands. cool.






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Simply got your database phpMyadmin and then open the table sales_flat_order and then simply remove tha data from this tabel and your test orders will be cleared. No need of any code or commands. cool.






                                      share|improve this answer













                                      Simply got your database phpMyadmin and then open the table sales_flat_order and then simply remove tha data from this tabel and your test orders will be cleared. No need of any code or commands. cool.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 16 '18 at 15:45









                                      Asif MehmoodAsif Mehmood

                                      337216




                                      337216

















                                          protected by Community Jan 4 '13 at 2:19



                                          Thank you for your interest in this question.
                                          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                          Would you like to answer one of these unanswered questions instead?



                                          Popular posts from this blog

                                          Florida Star v. B. J. F.

                                          Error while running script in elastic search , gateway timeout

                                          Adding quotations to stringified JSON object values