Reputation: 111
I am using Magento 1.9 and have an external application that takes care of shipping. Once the product is shipped a file is sent back to a listener I have written for Magento. I need to update the Magento Order status to complete and am using the following code which is based on earlier postings on Stackoverflow
$order_num = Mage::getModel('sales/order')->load($id);
$order_num->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
I am running into a problem here with the following
Uncaught exception 'Mage_Core_Exception' with message 'The Order State "complete" must not be set manually.
From what I can find this is because the order state is protected.
I have spent most of the day looking at possible solutions and can not work out how I can change the order status to complete and not throw the error.
I would appreciate it if anyone could give me a clue how to get this to work for 1.9
Regards
Richard
Upvotes: 0
Views: 1344
Reputation: 2762
use this code. it is works for me..
$order_num->setData('state', 'complete');
$order_num->setStatus('complete');
$history = $order_num->addStatusHistoryComment('', false);
$history->setIsCustomerNotified(false);
$order_num->save();
Upvotes: 1