在这里,我正在使用下面的代码删除订单,但它仍然显示在订单网格中。当我点击这个订单时,它显示“这个订单不再存在”。但我不需要在运行以下代码后显示订单。
<?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
$orders_object = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('increment_id', 100000025);
$orders_arr = $orders_object->getData();
if(!empty($orders_arr)){
$orders_data = $orders_arr[0];
$orderId = $orders_data['entity_id'];//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();
echo "deleted";
}else{
echo "no record";
}
?>