require_once "app/Mage.php";
    Mage::getSingleton('core/session', array('name' => 'frontend'));

    $session = Mage::getSingleton('customer/session');


            if (!empty($email) && !empty($password )) {
                    try {
                        $session->login($email, $password );
                        if ($session->getCustomer()->getIsJustConfirmed()) {
                            $this->_welcomeCustomer($session->getCustomer(), true);
                    } catch (Mage_Core_Exception $e) {
                        switch ($e->getCode()) {
                            case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                                $value = Mage::helper('customer')->getEmailConfirmationUrl($email);
                                $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                            case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                                $message = $e->getMessage();
                                $message = $e->getMessage();
                    } catch (Exception $e) {
                        // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
                } else {
                    $session->addError('Login and password are required.');


I am trying to programmatically login,it is successful but in product details page I get an error like this:

WHOOPS, OUR BAD... The page you requested was not found, and we have a fine guess why. If you typed the URL directly, please make sure the spelling is correct. If you clicked on a link to get here, the link is outdated.


I have created an Observer:

event name: controller_action_predispatch

And created an observer:

class Company_Module_Model_Customer_Observer {

    public function requireLogin($observer) {        
        $session = Mage::getSingleton('customer/session');
        $controllerAction = $observer->getEvent()->getControllerAction();
        $data = $controllerAction->getRequest()->getParams();
        Mage::getSingleton('core/session', array('name' => 'frontend'));
        $session = Mage::getSingleton('customer/session');
        $email = $data['username']; // or your user Id
        $password = $data['password']; // or your user Password
        $session->login($email, $password);

| improve this answer | |

I also face same problem after user login.

Finally , I resolved it by overriding the Mage_Reports_Model_Event_Observer method: public function catalogProductView(Varien_Event_Observer $observer) and added a return true;.

you just have to modify the config.xml file of your extension like below:

<?xml version="1.0"?>
    <frontend> <!-- Be careful to use <frontend> like above, <global> would not work -->

And it worked !!

| improve this answer | |
  • Its working for me.Is there any issue if this method always return true. – Jitendra Mohanta Nov 1 '16 at 14:37

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.