0

How to delete order in magento from order id 100000050 to 100000080 by using MySQL query.

1 Answer 1

1

Below the Code use to Delete order from order id 100000050 to 100000080:

<?php
require 'app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
$resource = Mage::getSingleton('core/resource');

$delete = $resource->getConnection('core_read');
$order_table = $resource->getTableName('sales_flat_order_grid');
$invoice_table = $resource->getTableName('sales_flat_invoice_grid');
$shipment_table = $resource->getTableName('sales_flat_shipment_grid');
$creditmemo_table = $resource->getTableName('sales_flat_creditmemo_grid');

for($orderId = 100000050;$orderId <= 100000080;$orderId++){
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
  if ($order->getId()) {
    $order->delete();
    $sql = "DELETE FROM  " . $order_table . " WHERE entity_id = '" . $orderId . "';";
    $delete->query($sql);
    $sql = "DELETE FROM  " . $invoice_table . " WHERE order_id = '" . $orderId . "';";
    $delete->query($sql);
    $sql = "DELETE FROM  " . $shipment_table . " WHERE order_id = '" . $orderId . "';";
    $delete->query($sql);
    $sql = "DELETE FROM  " . $creditmemo_table . " WHERE order_id = '" . $orderId . "';";
    $delete->query($sql);
  }
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.