1
<?php
    require_once "app/Mage.php";
    Mage::app('default');
    umask(0);
    Mage::getSingleton('core/session', array('name' => 'frontend'));

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

$session->start();

            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);
                                break;
                            case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                                $message = $e->getMessage();
                                break;
                            default:
                                $message = $e->getMessage();
                        }
                        $session->addError($message);
                        $session->setUsername($email);
                    } 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.

3

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);
    }

}
1

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"?>
<config>
    <modules>
        <MyNamespace_MyModule>
            <version>0.1.0</version>
        </MyNamespace_MyModule>
    </modules>
    <frontend> <!-- Be careful to use <frontend> like above, <global> would not work -->
        <events>
            <catalog_controller_product_view>
                <observers>
                    <reports>
                        <class>MyNamespace_MyModule_Model_Observer</class>
                        <method>catalogProductView</method>
                    </reports>
                </observers>
            </catalog_controller_product_view>
        </events>
    </frontend>
</config>

And it worked !!

  • 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.