Observer in magento

Send Email/ Sms on Change Order Status in Magento 


Steps 1. Create Module Suppose to "Sendsms_Custmail" 
copy and paste the following code into app/etc/modules/Sendsms_Custmail.xml


<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Sendsms_Custmail>
            <active>true</active>
            <codePool>local</codePool>
        </Sendsms_Custmail>
    </modules>

</config>

Steps 2. now Create the Observer.php file and put the following path 
app\code\local\Sendsms\Custmail\Model\

<?php
class Sendsms_Custmail_Model_Observer

    public function invoicedStatusChange($event)
    {
        $order = $event->getOrder();
$orderStatus = $order->getStatus();   
        //if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED)
        //if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE)
        if ($orderStatus == 'complete_order_shipped')




// put your logic here 


  
}

if ($orderStatus == 'complete_shippment_confirmed')

//$this->_sendStatusMail($event); 
 
// put your logic here 
  
}

    }




}

Steps 3. Create the config.xml file and paste the following the path 
app\code\local\Sendsms\Custmail\etc\

<config>
    <modules>
        <Sendsms_Custmail>
            <version>1.0.0</version>
        </Sendsms_Custmail>
    </modules>
 
    <global>
        <models>
            <custmail>
                <class>Sendsms_Custmail_Model</class>
            </custmail>
        </models>
        <events>
            <sales_order_save_commit_after>
                <observers>
                    <mail_status_change>
                        <type>singleton</type>
                        <class>custmail/observer</class>
                        <method>invoicedStatusChange</method>
                    </mail_status_change>
                </observers>
            </sales_order_save_commit_after>
        </events>
        
    </global>
</config>

Remark : Where app is the root folder of magento.

Conclusion: Once the order 's status change the observer will be execute    




Comments