Magento – Observer not firing if order status changes to complete

magento-1.9

I want to do some action when the order status changes to complete. Here is my code

app/etc/modules/changeorderstatus.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Changeorderstatus_status>
            <active>true</active>
            <codePool>local</codePool>
        </Changeorderstatus_status>
    </modules>
</config>

app/code/local/Changeorderstatus/status/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Changeorderstatus_status>
            <version>1.0</version>
        </Changeorderstatus_status>
    </modules>
    <global>
        <events>
            <sales_order_status_change>
                <observers>
                    <Changeorderstatus_observer>
                        <type>singleton</type>
                        <class>Changeorderstatus_status_Model_Observer</class>
                        <method>implementOrderStatus</method>
                    </Changeorderstatus_observer>
                </observers>
            </sales_order_status_change>
        </events>

    </global>
</config>

app/code/local/Changeorderstatus/status/Model/Observer.php

<?php
class Changeorderstatus_status_Model_Observer
{
    public function implementOrderStatus(Varien_Event_Observer $observer)
    {
        $status = $observer->getEvent()->getOrder()->getStatus();
        $originalData = $observer->getEvent()->getOrder()->getOrigData();
        $previousStatus = $originalData['status'];


        if (($status !== $previousStatus) && ($status == Mage_Sales_Model_Order::STATE_COMPLETE)) {
            exit();
        }
    }
}

If the state of any order changes to complete it should fire automatically.
I changed the order from canceled to completed manually but it is not firing

Best Answer

I think the problem here is the event you are triggering.

There is no event like sales_order_status_change, You should try with sales_order_save_after.

for me it works perfectly.