0

Freshly created and active user, after redirection to user cabinet logged out instantly:

                $this->_session = Mage::getSingleton('customer/session');
                $session = $this->_session;

                $customer = Mage::getModel('customer/customer')->setEmail($email)
                                                               ->save();
                // ^^^ successfully saves the customer entity

                $session->setCustomerAsLoggedIn($customer);

                // autoconfirm user
                if($customer->getConfirmation()!=null){
                    $customer->setConfirmation(null);
                }
                if($session->isLoggedIn()) {

                    Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl().'customer/account/');
                    return;
                }

it successfully redirects and shows the user cabinet and 'Log out' link is active, but if I open the magento front page in other tab of same browser it becomes clearly that customer is not logged in. Where to debug ? Thanks!

UPDATE

I am trying to login freshly created customer without password. Password attribute set to 'required'=>false in customer entity, via install script.

UPDATE 2

I was also forgot to $customer->save(); after $customer->setConfirmation(null); it is mandatory

  • I assume this is a snippet and that $session is set using $session = Mage::getSingleton( 'customer/session' ); ? – TJ Gamble at Jamersan Nov 11 '15 at 2:02
  • yes, this is Mage::getSingleton( 'customer/session' ); session object, edited snipped – Ilja Nov 11 '15 at 2:22
0

The actual customer login works similarly to your code but that function sets the website ID, make sure you are doing this.

$customer = Mage::getModel('customer/customer')
        ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->setEmail($email)->save();

$session->setCustomerAsLoggedIn($customer);
  • may i ask you if $session->login() method is necessary for user to set logged in? thanks! – Ilja Nov 11 '15 at 2:29
  • That's the way I have seen it in the past. However, if you look at the login function, it is doing something very similar to what you are doing. I did notice one difference. I update my answer to that difference. – TJ Gamble at Jamersan Nov 11 '15 at 2:39
0

In System > Configuration > General > Web > Session Cookie Management set Cookie Path as /

This makes your script and magento use same frontend cookie.

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.