Is there a way to programmatically reopen an order in Magento that has already reached complete or closed status? I have the following code which works for changing the status of an order, but I can’t get it to work for complete or closed orders.
// connect to magento
require_once('app/Mage.php');
umask(022);
Mage::app();
// check admin credentials
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$admin = Mage::getSingleton('admin/session');
if ( $admin->isLoggedIn() ) {
// update order status
$orderIncrementId = "100000001";
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
}
I got the current code here. On that page it says that it was tested with Magento 1.3.2.4, but I’m using Magento 1.6.x. Maybe that’s the issue?
Let me know if I need to provide more detail, and thanks for any help you can offer.
I don’t think that you’re having a Magento version issue here.
Under specific circumstances Magento simply just does not allow to switch the state of an order back to
Mage_Sales_Model_Order::STATE_PROCESSING.For example, usually you cannot save a
Mage_Sales_Model_Order::STATE_PROCESSINGstate to any order, which already has had refunds (creditmemos). Neither in 1.3.2.4, nor in 1.6.x.This is by-design.
Look at
Mage_Sales_Model_Order::_checkState()to see under which circumstances Magento forces resetting the order state toSTATE_COMPLETEorSTATE_CLOSED, respectively.To answer your question: you could achieve what you’re trying to do by overriding the
_checkState()method with your own method, which allows to setSTATE_PROCESSING.Be aware though, that this most probably will cause the creation of new state contexts which Magento neither knows nor expects or can handle.
If your changes wreak havoc, don’t blame me. You’ve been warned^^