How to get order id and other details of order for sales_order_payment_cancel event observer. i know how to get them for checkout_onepage_controller_success_action. But that method is not working in it. And showing this error.

Fatal error: Call to a member function getId() on a non-object in /home/orderitonline/public_html/includes/src/Barcatsia_Smsntf_Model_Observer.php on line 108



public function smsntf_cancel_order($observer){

        $order = $observer->getEvent()->getOrder();
        $orderIds = $order->getId();



        $layout = Mage::app()->getLayout();

            $order     = Mage::getModel('sales/order')->load($orderIds);            

        $message_for_send = Mage::getStoreConfig

        $http_url = Mage::getStoreConfig

        $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', 


        //replaceing %O% with Order Number
        $message_for_send = str_replace('%O%',100000000+intval($orderIds[0]),


        //replaceing %N% with Mobile Number
        $message_for_send = str_replace('%N%',$order->getdata


        //replaceing %A% with Grand Total
        $message_for_send = str_replace('%A%',$order->getdata('grand_total'),


        $http_url .='?'. Mage::getStoreConfig

        for($a=0; $a<sizeof($arr_params); $a++){

                    $http_url .= '&'.Mage::getStoreConfig

                    $http_url .= '&'.Mage::getStoreConfig



        //printing system->configuration inputs value
        //      echo Mage::getStoreConfig


            return false;
  • Can please show code of Barcatsia_Smsntf_Model_Observer – Amit Bera Feb 9 '16 at 9:50
  • try $Observer->getPayment()->getOrder()->getId() – Qaisar Satti Feb 9 '16 at 10:35

If you want to get order object from sales_order_payment_cancel at observer then you can try:


And from order object $OrderObject,you can get all order related details


just change $observer->getEvent()->getOrder() to $observer->getEvent()->getPayment()->getOrder()

  • when i am printing whole object data is too much long and page get hanged. that is why i am asking how to get order id – Rahul Chaurasia Feb 9 '16 at 9:57
  • for getting id try $order->getId() and Increment id $order->getIncrementId() – Amit Bera Feb 9 '16 at 9:58
  • why its give same error in third line? $payment = $observer->getEvent()->getPayment(); $order = $payment->getOrder(); $orderIds = $order->getId(); – Rahul Chaurasia Feb 9 '16 at 10:07
  • i changed this code $observer->getEvent()->getOrder() to $Observer->getEvent()->getPayment()->getOrder() Now its showing this error Fatal error: Call to a member function getEvent() on a non-object in – Rahul Chaurasia Feb 9 '16 at 10:41
  • just variable issue $Observer should be $observer – Amit Bera Feb 9 '16 at 10:55

Observers will give you different variables, so be careful when you use them. In your case, this observer only passes the payment information Mage::dispatchEvent('sales_order_payment_cancel', array('payment' => $this));. So what you are after is:

$payment = $observer->getEvent()->getPayment();
$order = $payment->getOrder();
  • i know its return order object. but how to get order id from order object – Rahul Chaurasia Feb 9 '16 at 9:56
  • Just do $orderId = $order->getId(); – Mayers Feb 9 '16 at 9:57
  • why its give same error in third line? $payment = $observer->getEvent()->getPayment(); $order = $payment->getOrder(); $orderIds = $order->getId(); – Rahul Chaurasia Feb 9 '16 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.