2

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.

  • Turn on error logging and check your var/log directory. It will most likely tell you what's wrong. – musicliftsme May 14 '15 at 19:20
  • This issue is not generating any log. – Eduardo May 14 '15 at 20:13
  • I discovered who I can use $order->setStatus("pending_recharge"); but when I use $order->setData("state", "pending_recharge"); my order status come back to "complete". I don't know if using only one of them I can have problems with other resources. – Eduardo May 21 '15 at 19:49
  • I have tested your code and it works for me, which does not help you. Here are just some observations of what is happening for me: Setting the values to pending_recharge ends up showing a "blank" in the order information, as I do not have pending_recharge set as a valid option in statuses. Status and state are different things. You can change the statuses via the admin for human reference, but the state is for the system (Magento) to understand - a single "state" can have different statuses. You shouldn't go changing "state" to anything other than system defaults. – Jon Holland May 22 '15 at 9:24
  • I just not understand why I can change order state from pending to pending_recharge but not from complete to pending_recharge. Anyway I'll see if the other side of code works just changing status. Thanks – Eduardo May 22 '15 at 10:19
2

Change order status programmatically

//Status Updated start here
require_once 'app/Mage.php';

// Retrieve order
$_order = new Mage_Sales_Model_Order();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$_order->loadByIncrementId($orderId);

umask(0);
Mage::app('default');
/*
    ##Magento Status List
    const STATE_NEW             = 'new';
    const STATE_PENDING_PAYMENT = 'pending_payment';
    const STATE_PROCESSING      = 'processing';
    const STATE_COMPLETE        = 'complete';
    const STATE_CLOSED          = 'closed';
    const STATE_CANCELED        = 'canceled';
    const STATE_HOLDED          = 'holded';
    const STATE_PAYMENT_REVIEW  = 'payment_review';
 */

$order = Mage::getModel('sales/order')->loadByIncrementID($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
$order->save();

You may change your code as below:

$order = Mage::getModel('sales/order')->loadByIncrementID(100000672);
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
$order->save();

Help: http://docs.magentocommerce.com/Mage_Sales/Mage_Sales_Model_Order.html

0

If your script is running stand-alone on the front end then save (write) functions are disabled by default. You can add this line of code to allow write operations on stand-alone scripts

define("ADMIN_STORE_ID",1); //or whatever your store ID is
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); //do this to allow us to write

or you might try

Mage::register('isSecureArea', 1);
  • I tried both ways but not worked. – Eduardo May 21 '15 at 18:01
  • I have tested your code and it works for me, which does not help you. Here are just some observations of what is happening for me: Setting the values to pending_recharge ends up showing a "blank" in the order information, as I do not have pending_recharge set as a valid option in statuses. Status and state are different things. You can change the statuses via the admin for human reference, but the state is for the system (Magento) to understand - a single "state" (such as new,processing,complete,etc) can have different statuses. – Jon Holland May 22 '15 at 9:29
  • You shouldn't go changing "state" to anything other than system defaults unless you have recoded the system to deal with it. – Jon Holland May 22 '15 at 9:32
0

Have you created a new state in magento? In magento community edition there is no state of an order as pending_recharge and by default state in magento are fixed. You can create new status and assign them to a state but there is no option to add new state

So once you update order status, magento will automatically update the state of the order. For example if your update the status to a order to processing it will automatically update the state of the order if its not already in processing state.

0

Try to put increment id in double inverted comma, and then just print the order by following code to check whether you are able to load the order object or not?

print_r($order->getData());

If you able to print the order data then it should change the order status.

  • I can get order data with no problems.... the problem occur when I change order status and save. The change of status is not taking effect. – Eduardo May 14 '15 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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