Create custom magento order status in module

Magento order status gives a clear idea to the position of the order. It will be helpful for operating team to take the necessary steps on that orders. In default, magento will provide the set of order state and status,


To know about order status click here.

These sometime will not help us to segregate based custom condition. In such cases we can add the custom order status. We can add the new order status through magento admin, but when we are adding the order status to third party we need to go with external module or extension development.

In order to add custom order status from magento module, the best place to add is through sql installer files. As you all know the one time db changes should come from that file. Here for example we need to track the magento fake orders as ‘Fake Order’ status to the ‘cancelled’ state. To add new order status first we need to define that order status in module config file.

Custom magento order status in config

                    <fake_cancelled translate="label">
                        <label>Fake Order</label>

So from the above code, ‘fake_cancelled’ defines the order status code and ‘Fake Order’ defines the label of the order status. The next step is to insert or update the new order status in database. To do that we have to use mysql-install php file or mysql-upgrade php file. If your module is the new module in the website, then you can add this script in your install file. For example you module version number is 1.0.0 then add this code in the file mysql4-install-1.0.0.php.

To add in existing module, you need to upgrade you module. For example assume your current version number of module is 1.0.0 and upgrading to 1.0.1 means, you need to add this code in mysql4-upgrade-1.0.0-1.0.1.php. Dont forget to change the config.xml file version number.


$installer = $this;


if (version_compare(Mage::helper('yourmodulename')->getMagentoVersion(), '1.4.2') > 0) {

    $statuses = array(
        'fake_cancelled' => Mage::getConfig()->getNode('global/sales/order/statuses/fake_cancelled')->asArray()

    foreach ($statuses as $statusCode => $statusInfo) {
        $data = array('status' => $statusCode, 'label' => (isset($statusInfo['label']) ? $statusInfo['label'] : ''));
        if($installer->getConnection()->fetchOne("select * from {$installer->getTable('sales/order_status')} where `status`='{$statusCode}'")){
			$where = array('status' => array('eq' => $statusCode));
			$installer->getConnection()->update($installer->getTable('sales/order_status'), $data, $where);
			$installer->getConnection()->insert($installer->getTable('sales/order_status'), $data);
        $data = array('status' => $statusCode, 'state' => 'canceled', 'is_default' => 0);
        if($installer->getConnection()->fetchOne("select * from {$installer->getTable('sales/order_status_state')} where `status`='{$statusCode}'")){
			$where = array('status' => array('eq' => $statusCode));
			$installer->getConnection()->update($installer->getTable('sales/order_status_state'), $data, $where);
			$installer->getConnection()->insert($installer->getTable('sales/order_status_state'), $data);


When you refresh the page this code will add new order status and assign that order status to cancelled order status.