Skip to content

Instantly share code, notes, and snippets.

@pawel-dubiel
Created March 15, 2016 23:16
Show Gist options
  • Save pawel-dubiel/3801d4c7ac60294d98f2 to your computer and use it in GitHub Desktop.
Save pawel-dubiel/3801d4c7ac60294d98f2 to your computer and use it in GitHub Desktop.
Magento change order status
<?php
require_once 'app/Mage.php';
Mage::app("default");
/**
*
* SELECT DISTINCT(status) FROM sales_flat_order ;
*
* SELECT DISTINCT(state) FROM sales_flat_order ;
* SELECT DISTINCT(status) FROM sales_flat_order_grid;
*
* plain queries if you cant change from the code due some other problems
* UPDATE sales_flat_order_grid SET status='' WHERE increment_id='';
* UPDATE sales_flat_order SET state = '', status = '' WHERE increment_id='';
*
*/
$orders = []; // array of increment ids of the order
foreach ($orders as $id) {
$order = Mage::getModel('sales/order')->loadByIncrementId($id);
try {
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
// /**
// * change order status to 'Pending'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_NEW, true)->save();
//
// /**
// * change order status to 'Pending Paypal'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
//
// /**
// * change order status to 'Processing'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
//
// /**
// * change order status to 'Completed'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
//
// /**
// * change order status to 'Closed'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_CLOSED, true)->save();
//
// /**
// * change order status to 'Canceled'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
//
// /**
// * change order status to 'Holded'
// */
// $order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();
} catch (Exception $e) {
echo $e->getMessage() . '<br />';
}
// another way less forced
// if ($order->canCancel()) {
// try {
// $order->cancel();
// $order->save();
// } catch (Exception $e) {
// echo $e->getMessage() . '<br />';
// }
// } else {
// echo 'Cannot cancel order' . $id;
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment