How to register more than 1 event observer in config.xml If called methods are in same class & file.
When using both observer seprately(registering them seprately) both are working. But when both are enabled can't complete checkout process. After selecting payment information continue buton not working in rwd theme.
first observer is doing something when payment made successfully. And second observer is printing some text before page load. When using both seprately both are working fine. But when using both at once. Second observer is printing text before body load as it should do. But checkout process can't complete so i don't know second will do work as it should do or not.
when i disable my module checkout is working. Even 1 remove 1 observer registry from config.xml then checkout is also working.
<events> <checkout_onepage_controller_success_action> <observers> <Barcatsia_Smsntf_Model_Observer_customFunction> <type>singleton</type> <class>Barcatsia_Smsntf_Model_Observer</class> <method>customFunction</method> </Barcatsia_Smsntf_Model_Observer_customFunction> </observers> </checkout_onepage_controller_success_action> <controller_action_layout_load_before> <observers> <Barcatsia_Smsntf_Model_Observer_cancelorder> <type>singleton</type> <class>Barcatsia_Smsntf_Model_Observer</class> <method>smsntf_cancel_order</method> </Barcatsia_Smsntf_Model_Observer_cancelorder> </observers> </controller_action_layout_load_before> </events>
Observer.php
<?php
class Barcatsia_Smsntf_Model_Observer
{
public function customFunction(Varien_Event_Observer $observer)
{
if(Mage::getStoreConfig('testsection/smsntf/Smsntf_module_activation')){
// $order = $observer->getEvent()->getOrder();
//here you can add your custom code
$layout = Mage::app()->getLayout();
//IF{ //its working now if is working now
$messageBlock = $layout->createBlock('core/template', 'smsntf_test');
$messageBlock->setTemplate('smsntf/red/event_observer/event_observer.phtml');
$layout->getBlock('before_body_end')->append($messageBlock);
//}ELSE{
// $layout->getUpdate()->addHandle('custom_layout_handle'); //refrencing here layout.xml handle
//}
// $footer = $layout->getBlock('before_body_end');
// $footer->setCacheKey(sha1($footer->getCacheKey() . '-payment-message'));
//NOW GETTING ORDER ID AND OTHER ORDER DETAIL
$orderIds = $observer->getData('order_ids');
// $order = Mage::getModel('sales/order')->load($_orderId);
// $customer = Mage::getModel('customer/customer')->load($order->getData('customer_id'));
$orderIds = $observer->getData('order_ids');
// foreach($orderIds as $_orderId){
$order = Mage::getModel('sales/order')->load($orderIds);
// print_r($order ->getdata('grand_total'));
// print_r($order ->getdata());
// }
//NOW GETTING ORDER ID AND OTHER ORDER DETAIL
$message_for_send = Mage::getStoreConfig('testsection/smsntf/Smsntf_text_field_msg');
$http_url = Mage::getStoreConfig('testsection/smsntf/Smsntf_text_field_api_calling_url');
$arr_params = array('Smsntf_text_field_authkey', 'Smsntf_text_field_mobile', 'Smsntf_text_field_senderid', 'Smsntf_text_field_routeid', 'Smsntf_text_field_additional', 'Smsntf_text_field_additional', 'Smsntf_text_field_additional1', 'Smsntf_text_field_additional2', 'Smsntf_text_field_additional3', 'Smsntf_text_field_additional4');
//replaceing %O% with Order Number
$message_for_send = str_replace('%O%',100000000+intval($orderIds[0]),$message_for_send);
//replaceing %N% with Mobile Number
$message_for_send = str_replace('%N%',$order->getdata('customer_firstname'),$message_for_send);
//replaceing %A% with Grand Total
$message_for_send = str_replace('%A%',$order->getdata('grand_total'),$message_for_send);
$http_url .='?'. Mage::getStoreConfig('testsection/smsntf/Smsntf_text_field_Msg_prm').'='.urlencode($message_for_send);
for($a=0; $a<sizeof($arr_params); $a++){
if(trim(Mage::getStoreConfig('testsection/smsntf/'.$arr_params[$a]))!=''){
if(trim($arr_params[$a])!='Smsntf_text_field_mobile')
$http_url .= '&'.Mage::getStoreConfig('testsection/smsntf/'.$arr_params[$a]);
else
$http_url .= '&'.Mage::getStoreConfig('testsection/smsntf/'.$arr_params[$a]).'='.$order->getBillingAddress()->getData('telephone');
}
}
// echo $http_url;
//printing system->configuration inputs value
// echo Mage::getStoreConfig('testsection/smsntf/active');
$this->send_sms($http_url);
}else{
return false;
}
}
public function send_sms($feed_url/*, $rauth_key, $amobile, $hmsg, $uid, $lid, $content_type*/){
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
$curl = new Varien_Http_Adapter_Curl();
$curl->setConfig(array(
'timeout' => 30
));
// $feed_url = 'http://sms.vtechnologies4u.in/rest/services/sendSMS/sendGroupSms?AUTH_KEY=48cdfa49d561561cb65dc5175c3aea&mobileNos=7080557519&message=now+its+working_ninee_step&senderId=Vtechn&routeId=1&smsContentType=english';
// $feed_url = 'http://sms.vtechnologies4u.in/rest/services/sendSMS/sendGroupSms?AUTH_KEY='.$rauth_key.'&mobileNos='.$amobile.'&message='.$hmsg.'&senderId='.$uid.'&routeId='.$lid.'&smsContentType='.$content_type;
$curl->write(Zend_Http_Client::GET, $feed_url, '1.0');
$data = $curl->read();
if ($data === false) {
return false;
}
$data = preg_split('/^r?$/m', $data, 2);
$data = trim($data[1]);
$curl->close();
try {
// $xml = new SimpleXMLElement($data);
// Parse the XML FEED and output the data
// echo "Connection done successfully";
}
catch (Exception $e) {
// echo $e->getMessage();
}
}
public function smsntf_cancel_order(){
echo "i will visile every time befoe page load";
}
}