0

I have an observer for

checkout_onepage_controller_success_action

which will call the method :

sendSmsOnSuccess()

The method is as follows :

public function sendSmsOnSuccess($observer)
{
    if($order->getStatus()== ($this->ORDER_STATUS_COMPLETE) || $order->getStatus()== ($this->ORDER_STATUS_PROCESSING))
    {
      if(!$this->sandbox){
            $helper->prepareSmsData($orderid);
        }
    }
}

The prepareSmsData method :

public function prepareSmsData($orderid,$showAlert=false)
{
  // after some processing the data 
 return($this->sendSms($sms_text,$customerData->getTelephone(),$showAlert));
}

The sendSms Method

private function sendSms($text,$gsm_num,$showAlert)
{
   if(!Mage::registry('messageDisplayed')){ 
   Mage::register('messageDisplayed',true); 
   $session = Mage::getSingleton('core/session'); 
   $message = 'Coupon code & Redeem code sent to your mobile number ('.$gsm_num.')';
   $session->addSuccess($message);
    if($showAlert)
          {
              echo('<script language="JavaScript" type="text/javascript">
                    alert("Message sent to Mobile Number");
                    window.close();
              </script>');
          }
   }
}

The problem is : the successMessage is never displayed on frontend, if i var_dump($session) with in the sendSms method, i can see the success message. i tried to display successMessage even from the Observer.php. but not showing at all

1 Answer 1

0

There are small modification needed at your code:

checkout_onepage_controller_success_action event give only array of order ids order_ids.

Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));

You cannot get directly Order object from Observer for this event,you need call sales/order model by those ids

public function sendSmsOnSuccess($observer)
{
    $order_ids=$observer->getEvent()->getOrderIds();
    if(!is_array($order_ids)):
        return;
    endif;

        foreach ($order_ids as $eachOrderId) {

            $order=Mage::getModel('sales/order')->load($eachOrderId);   
            if($order->getStatus()== ($this->ORDER_STATUS_COMPLETE) || $order->getStatus()== ($this->ORDER_STATUS_PROCESSING))
            {
              if(!$this->sandbox){
                    $helper->prepareSmsData($orderid);
                }
            }
        }
}
2
  • still not working, :( & why should i use foreach since there will be only one orderid ?
    – Shan
    Commented Apr 28, 2016 at 6:59
  • I tried Mage::getSingleton('checkout/session')->addSuccess('Blah Blah Blah'); inside sendSmsOnSuccess() method by commenting all other lines. still not showing
    – Shan
    Commented Apr 28, 2016 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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