I am trying below code for login to site after entering email & password in pop up. Login is working. but pop up is not hiding after successfull login.

protected function _createProduct() 

   try { 
         if(isset($login) && (is_array($login) && !empty($login)) || ($login!="")){ 
         $session->login($login['username'], $login['password']); 
         $result['redirect'] = $this->_getRefererUrl() ? $this->_getRefererUrl() : Mage::getUrl('customer/account', array( 
         '_secure' => true 
                $result['success']  = true; 
                $customerId         = Mage::getSingleton('customer/session')->getCustomerId(); 
          $customerId = ""; 

         if ($doSave) 

        return $product;                   

       catch () {  }                                   




Fatal error : Call to a member function addJs() on a non-object in line


if anyone want to look full controller code : http://pasted.co/9887d0db

  • @BenCrook we need to hide the pop up only after successfull login, so we are trying this way, means once user enter correct email id & password , than we are using that code : Mage::app()->getLayout()->getBlock('head')->addJs('js/hide/here.js'); in controller function, so that it will hide pop up after succesfull login, otherwise it will not hide pop up.....
    – user52996
    Commented May 4, 2017 at 12:59
  • Completely ignore my previous comment, I presumed this was Magento 2 sorry! I think you would be better to handle this with AJAX, so if the user successfully logs in you run your JS, else you don't. But hopefully someone has an easier fix than that.
    – Ben Crook
    Commented May 4, 2017 at 13:16
  • @BenCrook when you get free time, please help me with ajax code....
    – user52996
    Commented May 4, 2017 at 13:58
  • I don't know PHP so I can't help with creating an AJAX controller sorry, from a front-end perspective you need to fire the AJAX when the customer hits the login button, and that can return whether the user is logged in. Then you can write an if statement to detect whether the user is logged in and hide the popup. A guide like this one might help.
    – Ben Crook
    Commented May 4, 2017 at 14:27
  • @BenCrook Thankyou for the link.....
    – user52996
    Commented May 5, 2017 at 17:47

1 Answer 1


Change createSimpleProductAction following code

public function createSimpleProductAction()
    $product = $this->_createProduct(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
    echo 'See getId() . '">created simple product';

That means you must need to load layout before

  • actually i needed to use your code in proper function : public function createSimpleProductAndRedirectAction() thanks, now the error removed , but pop up is not hiding....
    – user52996
    Commented May 5, 2017 at 7:23
  • If you use ajax, then pass value from action and make decision show/hide your div.
    – Sohel Rana
    Commented May 5, 2017 at 7:31
  • as you said, in controller action, after code of login successfull : $result['success'] = true; i am passing this code : Mage::app()->getLayout()->getBlock('head')->addJs('js/hide/here.js'); & i am using jquery to hide the pop up,
    – user52996
    Commented May 5, 2017 at 7:46

Your Answer

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