1

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());
        $this->getCustomerSession()->addSuccess(
            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)
        );

        // WHAT SHOULD I PUT HERE TO LOGIN CUSTOMER?
        // 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());
        $this->getCustomerSession()->loginById($customer->getId());
    }
    return $this;
}
2

Here how you can login a customer automatically

Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);

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.

0

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');
$session->setUsername('username');

And add in the information you want.

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.