Order State and Status in Magento

Many of you might have come across the requirement, where they needed to change the order status dynamically.

Difference between order state and status
State is used by Magento to tell if the order is new, processing, complete, holded, closed, canceled etc.; while Statuses are the one that YOU would be defining at the back-end in System -> Order Statuses. Magento displays order STATUSES and not STATES in the back-end order detail page to let you know which status is assigned as per your mapping. Remember, multiple statuses can be mapped with one state, while vice verse is not possible.

Please check this file /app/code/core/Mage/Sales/etc/config.xml (I have refered Magento 1.4)

Also refer this in Magento Wiki Order Management

<order>
                <statuses>
                    <pending translate="label"><label>Pending</label></pending>
                    <pending_payment translate="label"><label>Pending Payment</label></pending_payment>
                    <processing translate="label"><label>Processing</label></processing>
                    <holded translate="label"><label>On Hold</label></holded>
                    <complete translate="label"><label>Complete</label></complete>
                    <closed translate="label"><label>Closed</label></closed>
                    <canceled translate="label"><label>Canceled</label></canceled>
                    <fraud translate="label"><label>Suspected Fraud</label></fraud>
                </statuses>
                <states>
                    <new translate="label">
                        <label>New</label>
                        <statuses>
                            <pending default="1"/>
                        </statuses>
                        <visible_on_front/>
                    </new>
                    <pending_payment translate="label">
                        <label>Pending Payment</label>
                        <statuses>
                            <pending_payment default="1"/>
                        </statuses>
                    </pending_payment>
                    <processing translate="label">
                        <label>Processing</label>
                        <statuses>
                            <processing default="1"/>
                        </statuses>
                        <visible_on_front/>
                    </processing>
                    <complete translate="label">
                        <label>Complete</label>
                        <statuses>
                            <complete default="1"/>
                        </statuses>
                        <visible_on_front/>
                    </complete>
                    <closed translate="label">
                        <label>Closed</label>
                        <statuses>
                            <closed default="1"/>
                        </statuses>
                        <visible_on_front/>
                    </closed>
                    <canceled translate="label">
                        <label>Canceled</label>
                        <statuses>
                            <canceled default="1"/>
                        </statuses>
                        <visible_on_front/>
                    </canceled>
                    <holded translate="label">
                        <label>On Hold</label>
                        <statuses>
                            <holded default="1"/>
                            <fraud/>
                        </statuses>
                        <visible_on_front/>
                    </holded>
                </states>
            </order>

I am displaying here the code to change the state and status of the order dynamically

Before modifying order status in some code, make sure that current order state allows status wanted. It is possible to change both state and status with setState method

$orderId = 3226; //order id
$order = Mage::getModel('sales/order')->load($orderId); //load order				
$state = 'complete';
$status = $state;
$comment = "Changing state to $state and status to $status Status";
$isCustomerNotified = false; //whether customer to be notified
$order->setState($state, $status, $comment, $isCustomerNotified);	
//$order->setStatus($status);	//can also use this to change only status
try { 
$order->save();
echo "<br />State and Status Updated";

}catch (Exception $e)
{
	echo $e->getMessage();
}

Hope its useful.

Also I found this useful

5 thoughts on “Order State and Status in Magento

  1. Thanks! Now I understand the difference between states and statuses. I’m new to Magento and I’m trying to read about this platform.
    If I need to change order status, should I do it programmatically? Or is it better to use some extensions (like order status by Amasty, I’ve just found it while researching this topic)? Please share you thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top