Home » Magento14 July 2010

Magento: How to change order status programmatically?

This article shows how to change your order status programmatically in Magento.

First, you need to load your order. You can load order by either order_id or order_increment_id.

Load order by “order id”

Load order by “order increment id”

Change order status to Complete

Change the order status to pending, processing, canceled, closed, holded, etc.

Cancel an order

Hold an order

Unhold an order

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Pingback: Tweets that mention Magento: How to change order status programmatically? | Mukesh Chapagain's Blog -- Topsy.com()

  • Hey!

    I receive the error:

    Uncaught exception ‘Mage_Core_Exception’ with message ‘The Order State “closed” must not be set manually.’

    Can you help?

    Chris.

  • zimba

    i have the same problem

    Uncaught exception ‘Mage_Core_Exception’ with message ‘The Order State “closed” must not be set manually.’

    Can you help?

    zimba

  • Maks

    Hi men !

    If you have “Closed” and not “closed” it’s works !

    => Try this : “ucfirst(Mage_Sales_Model_Order::STATE_CLOSED)”

  • Shaniabudi

    This method doesn’t seem to work…
    I’ve tried :
    $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();

    and got :
    Uncaught exception ‘Mage_Core_Exception’ with message ‘The Order State “complete” must not be set manually.’

  • Adevillaine

    This is because STATE_CLOSED and STATE_COMPLETED cannot be set with setState.

    Mage_Sales_Model_Order explicitly set an exception when you try to set them with the method just mention.

    I also need to set the state but to completed. The ucfirst is not really a good solution because what you are actually doing is to change the constant value, and breaks some validations Magento do.

    This is for Magento >= 1.4.0.1

  • Femiji

    the
    $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
    does not work in magento 1.4.2

    throws ‘The Order State “complete” must not be set manually.’

  • Josie

    This program is for the birds

  • But this wil work

    $this->_setState(self::STATE_COMPLETE, true, ”, $userNotification);

  • Vishal

    How to set the product status as ‘DISABLED’ programatically????

  • deter

    Hi Mukesh, thanks for your posts about magento programming (they helped me very much). But in this case, when I call $order->save() method, it throws an error:

    Fatal error: Mage_Core_Model_Session_Abstract::addMessage(): The script
    tried to execute a method or access a property of an incomplete object.
    Please ensure that the class definition
    “Mage_Core_Model_Message_Collection” of the object you are trying to
    operate on was loaded _before_ unserialize() gets called or provide a
    __autoload() function to load the class definition in /myweb/app/code/core/Mage/Core/Model/Session/Abstract.php
    on line 238

    When not calling save() method, this error doesnt show, but order status isn´t saved :(
    Any solution for this?

    //sorry for my English

  • deter

    I reply for myself – there was session_start() used twice at start of the script. Sorry for mess, you can delete my posts.

  • deter

    I reply for myself – there was session_start() used twice at start of the script. Sorry for mess, you can delete my posts.

  • Sanket Shah

    This thing is not working. can you suggest some alternate method?

  • Sanket Shah

    This thing is not working. Can you please suggest some alternate method?

  • Ramesh589

    not working , can u say in detail

  • Hone

    $order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);

  • Try also, 

    $order->setData(‘state’, Mage_Sales_Model_Order::STATE_COMPLETE);
    $order->save();

  • Sam

    which php file do i put this code in?
    magento 1.5
    i am trying to change status of orders which have particular shipping method
    for eg.
    $order = Mage::getModel(‘sales/order’)->getCollection()->addFieldToFilter(‘shipping_description’,’some_random_shipping_name’))->getFirstItem();

    then I want to set the status which I have created using the new feature in 1.5 and assign that status to these orders.
     Are there any ideas how can I do this?
    Thanks

  • Bassam

    Can we do the same thing (set order state to “complete” or “processing”) using SOAP instead of API?

  • Pingback: 2Coding Magento: How to change order status programmatically? | 2Coding()

  • Sajid

    I have very strange issues , when I am trying to change order state of paypal to hold,pending to anything it get change but on just second exec it turns into processing.

    even I wrote code in succes.phtml if order is paypal thn change order state to pending my debug text says

    $orderFraud=Mage::getSingleton(‘core/session’)->getSuspectedFraud();
                            if ($orderFraud) {
                                                    $order = Mage::getSingleton(‘sales/order’);
                                                   
                                        $order->loadByIncrementId($this->getOrderId());
                                        //var_dump($order);
     
                                                    echo “I am in isOrderFraud going to change status before :”.$order->getStatus();
                                        $order->setState(Mage_Sales_Model_Order::STATE_NEW, true)->save();
                                                    echo “I am in isOrderFraud going to change status after :”.$order->getStatus();
                            }
     
    output I am in isOrderFraud going to change status before :processingI am in isOrderFraud going to change status after :pendingbut when I go to admin or my account order state is pending . this code work fine for my instance but on client its not  any suggestion ?

  • You are the best

  • eve

    These actually works.Thanks!

  • ramesh

    Thank you budy