I would like to send an sms on every successful registration. Below is my code. But I am not sure whether the method is triggered after successful registration.
app\etc\modules\Php_Sms.xml
<?xml version="1.0"?>
<config>
<modules>
<Php_Sms>
<active>true</active>
<codePool>local</codePool>
<version>0.0.1</version>
</Php_Sms>
</modules>
</config>
Inside local code pool, I have created namespace as Php and module as Sms.
code\local\Php\Sms\etc\config.xml as below
<config>
<modules>
<Php_Sms>
<version>0.0.1</version>
</Php_Sms>
</modules>
<global>
<events>
<customer_register_success>
<observers>
<Php_Sms_customer_register_success>
<type>singleton</type>
<class>Php_Sms_Model_Observer</class>
<method>customerRegisterSuccess</method>
</Php_Sms_customer_register_success>
</observers>
</customer_register_success>
</events>
</global>
</config>
code\local\Php\Sms\Model\Observer.php as below
<?php
class Ucs_GlobalSms_Model_Observer {
public function customerRegisterSuccess(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$customer = $event->getCustomer();
$email = $customer->getEmail();
Mage::log('Successfully logged in', null, 'mylogfile.log');
if($email) {
}
}
}
?>
Mage\customer\controllers\AccountController.php
/**
* Dispatch Event
*
* @param Mage_Customer_Model_Customer $customer
*/
protected function _dispatchRegisterSuccess($customer)
{
Mage::log('Successfully logged in'.$flag, null, 'syncProduct.log');
Mage::dispatchEvent('customer_register_success',
array('account_controller' => $this, 'customer' => $customer)
);
}
But mylogfile.log is not at all creating. I guess customerRegisterSuccess is not triggered, should I do something to enable _dispatchRegisterSuccess method?
My questions are,
- Will magento log work on Observer.php?
- How to know whether my custom method triggered?
- Why my sms is not sending? (No issues with SMS api. It works fine in core php file)
Best Answer
you have to change
<class>Php_Sms_Model_Observer</class>
to<class>Php_Sms_Model</class>