I have two environments, production and development. And I tried to run this code on root of Magento:
<?php
require_once "app/Mage.php";
Mage::app('default');
error_reporting(E_ALL);
ini_set('display_errors', 1);
umask(0);
$order = Mage::getModel("sales/order")->loadByIncrementId(100000672);
$order->setData("state", "pending_recharge");
$order->setStatus("pending_recharge");
$history = $order->addStatusHistoryComment('A ser executada a rotina de recarga.', false);
$history->setIsCustomerNotified(false);
$order->save();
I am just changing the Increment Id from one environment to another. The acctually status and states of order is "complete".
On development the code is working, but on production the status of order does't save.
I don't know how debug to find this error, I believe it to be in the database, maybe some foreign key.
Another thing I noticed that I have two payment methods and this only happening with one.
And I checked who pending_recharge status exist in both environments.
Best Answer
Change order status programmatically
You may change your code as below:
Help: http://docs.magentocommerce.com/Mage_Sales/Mage_Sales_Model_Order.html