During guest checkout, when customer places order, he gets two emails - first one is email confirmation ("Please activate your account") and second one - information about order.

Is there any way to programatically log in this new user on a site directly after the checkout? (so after the checkout he can go to customer/account without having to log in)

In Mage_Checkout_Model_Type_Onepage, there is function:

protected function _involveNewCustomer()
    $customer = $this->getQuote()->getCustomer();
    if ($customer->isConfirmationRequired()) {
        $customer->sendNewAccountEmail('confirmation', '', $this->getQuote()->getStoreId());
        $url = Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail());
            Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.', $url)

        // I tried: $this->getCustomerSession()->loginById($customer->getId()); , but it doesn't work and just redirects to cart page

    } else {
        $customer->sendNewAccountEmail('registered', '', $this->getQuote()->getStoreId());
    return $this;

2 Answers 2


Here how you can login a customer automatically


But I don't understand something in your logic.
You are requiring the customers to validate their account after creating it, but if a user creates an account while in the checkout process then you don't want him to confirm his e-mail.

If you won't to skip the e-mail validation step just edit the setting in System->Configuration->Customer configuration.


You might want to have a look at how it's done in the core of Magento, what you'll find is this :

$session = Mage::getSingleton('customer/session');
$session->login('username', 'password');

And add in the information you want.

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.