Thứ Ba, 11 tháng 3, 2014

Magento Delete order

magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders magento delete orders

Delete Magento orders

How to delete Magento orders

Magento by default does not provide a function to delete Magento orders. Fortunately, there are many plug-ins are available that would add option to delete Magento orders in grid actions drop-down.

Delete Magento orders
While this decision makes good sense, many users are still in need of this functionality to delete test orders. It’s not simple to delete Magento orders isn’t a simple task. Because you have to remove invoices, creditnotes and shipments firstly that related to order you want to delete. 
I have found a scirpt for that task.
Hope this useful!

<?php
// comment the following two lines before execute shis script
echo 'No access permission';
exit;

$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);

// order increment ID you want to delete. Delete one Order to execute this order once.
$incrementId = 100000037;
  
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
$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();
}
if ($order->delete()) {
      echo 'the Order of order # ' . $incrementId . ' has been deleted from database.';
} else {
      echo 'Deletion failed.';
}

?>
You also use this script to delete all Magento canceled orders.
$collection = Mage::getResourceModel('sales/order_collection')
            ->addAttributeToSelect('*')
            ->setPageSize(1000)
            ->addFieldToFilter('status', 'canceled')
             ->load();

foreach ($collection as $col) {
  Mage::log($col->getIncrementId() . ' order deleted ');
    try {
         $col->delete();
    } catch (Exception $e) {
        throw $e;
    }
}

Không có nhận xét nào:

Đăng nhận xét