You often need to change order status programmatically when working with a project which requires to transfer order between Magento site and a third party system. Usually, Magento sends order info to processing system, this system sends back result of that order: ship, reject... And we need to change order status programmatically here.
First, you will need load your order. Here are 2 ways to load order with order id and order increment id.
$orderId = YOUR_ORDER_ID; $order = Mage::getModel('sales/order')->load($orderId);
$orderIncrementId = YOUR_ORDER_INCREMENT_ID; $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
Now we will see how to change order status. Basic method for doing this will be:
And you can see a list of order status here:
- Pending: Mage_Sales_Model_Order::STATE_NEW
- Pending Payment: Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
- Processing: Mage_Sales_Model_Order::STATE_PROCESSING, true
- Complete: Mage_Sales_Model_Order::STATE_COMPLETE
- Closed: Mage_Sales_Model_Order::STATE_CLOSED
- Canceled: Mage_Sales_Model_Order::STATE_CANCELED, true
So, to change an order to complete, you will write this code: