0

This is my observer function for customer_register_success and customer_save_after event it execute my custom url but i m getting blank session

$customerData = Mage::getSingleton('customer/session')->getCustomer();


public function doSomething($observer)
{    
 $AccountController = $observer->getEvent()->getAccountController();
  $Customer = $observer->getEvent()->getCustomer();

      $session=Mage::getSingleton('customer/session');
   $session->setBeforeAuthUrl(Mage::getSingleton("mymodule/session")->getCompurl().'state_new/1');
    if (!$Customer->getCustomerActivated()) {
    }
    else{
       //$session->setCustomerAsLoggedIn($Customer);
       $response1 = Mage::app()->getResponse(); // observers have event args



        $dataarray = Mage::getSingleton("mymodule/session")->getData_array();
        $sampleid=$dataarray['sampleid'];

        $state=$dataarray['state'];
        if($state==1)
        {
          $collection=Mage::getSingleton('mymodule/mymodule')->customisesaved($sampleid);
        if($collection)
        {
            $url=Mage::getUrl('mymodule/mymodule/customshow');
             Mage::log($url,null,"url.log");            
                Mage::app()->getFrontController()->getResponse()->setRedirect($url);
             Mage::app()->getResponse()->sendResponse();
             exit;
        }          

    }

}
}

Suggest me some solution.print_r($url) $url has my custom controller url but not executing it.This is my custom controller where i want to redirect and continue the process

public function customaddAction()
    {
     $sampleid=$this->getRequest()->getParam('sampleid');

    $login_new=$this->getRequest()->getparam('state_new');
        Mage::getSingleton("mymodule/session")->setData('data_array',array('sampleid'=>$sampleid,'state'=>1));
            if((!Mage::helper('customer')->isLoggedIn())||(!$login_new))
        {
        Mage::getSingleton("mymodule/session")->setData('data_array',array('sampleid'=>$sampleid,'state'=>1));
           Mage::getSingleton("mymodule/session")->setData('compurl',Mage::helper('core/url')->getCurrentUrl());
            Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
            $this->_redirect('customer/account/login');

        }
     if((Mage::helper('customer')->isLoggedIn())||($login_new==1))
        {
        Mage::getSingleton("mymodule/session")->setData('data_array',array('sampleid'=>$sampleid,'state'=>0));
         $sampleid=$this->getRequest()->getParam('sampleid');

          $collection=Mage::getSingleton('mymodule/mymodule')->customisesaved($sampleid);
        if($collection)
        {
        $this->_redirect('mymodule/mymodule/customshow');
        }
        else{
                 $this->_redirectReferer();
            }
        }
    }
1
  • Do you want redirect to customshow or customadd action? Commented Dec 9, 2018 at 6:21

1 Answer 1

0

Try below code:

Mage::app()->getFrontController()->getResponse()->setRedirect($url);
    Mage::app()->getResponse()->sendResponse();
    exit;
5
  • thanks for answer it doesn't redirect or do anything but when i do inspect element it shows my custom url but the user is not loggedin and give Error: Syntax error, unrecognized expression: .ytmpa-
    – coder
    Commented Aug 26, 2016 at 4:52
  • I have doubt on this line $url = Mage::getSingleton("mymodule/session")->getCompurl().'state_new=1' please print this url in log for check your Url by using: Mage::log($url,null,"url.log")
    – Arunendra
    Commented Aug 26, 2016 at 4:58
  • please see my updated question.I have included the controller function that i am calling from the $url
    – coder
    Commented Aug 26, 2016 at 5:07
  • Why you need to redirect it on your controller? when you can do the same thing in your observer
    – Arunendra
    Commented Aug 26, 2016 at 5:34
  • please see my updated question i am executing my code inside observer but it does not execute it
    – coder
    Commented Aug 26, 2016 at 6:32

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.