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