Magento – how to delete test orders in Magento

ce-1.7.0.2magento-1.7orders

I am using Magento 1.7.0.2.I would like to delete the orders in my Magento site. I have tried to delete it in database but that is not the proper way.
Thanks in advance!

Best Answer

Use this extension for delete order.

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

Or you can use below code to delete your order.

error_reporting(E_ALL | E_STRICT);

$mageFilename = 'app/Mage.php';

require_once $mageFilename;

umask(0);

Mage::app('admin')->setUseSessionInUrl(false);      

$collection = Mage::getModel('sales/order')->getCollection();
foreach ($collection as $data) {
    $id = $data['increment_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.";
Related Topic