I have something but this checks if in the cart are products:
public function customerLogin(Varien_Event_Observer $observer)
{
if (Mage::helper('customerredirect')->isEnabled() && !Mage::getSingleton("core/session")->getRedirectregister()){
$lasturl = Mage::getSingleton('core/session')->getLastUrl();
if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout/cart') === false){
if (! preg_match("#customer/account/create#", $lasturl) && Mage::helper('customerredirect')->isoptionEnabled('login_customerredirect')) {
if($this->_CustomerGroup()) {
$_session = $this->_getSession();
$_session->setBeforeAuthUrl(Mage::helper('customerredirect')->setRedirectOnLogin());
}
}
}
}
Mage::getSingleton("core/session")->setRedirectregister(false);
}
and I add this in the /app/design/frontend/base/default/template/checkout/onepage/link.phtml
<?php if ($this->isPossibleOnepageCheckout() && Mage::getSingleton('customer/session')->isLoggedIn()):?>
<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Proceed to Checkout')) ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo $this->getCheckoutUrl() ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php else: ?>
<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Proceed to Checkout')) ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo Mage::getUrl('customer/account/login'); ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php endif?>
All I want to do is when I press on the Proceed to Checkout if the user is not login to be redirected to login and the autoredirect to checkout onepage.
After more searches i found something that need to be put in the onepage checkout:
if (!$this->helper('customer')->isLoggedIn()) {
header("Location: /customer/account/login/");
exit();
}
but this is generally how I can implement this for my needs?
Edit: Maybe this can be a solution?
https://magento.stackexchange.com/a/64085/22840
Thank you
Best Answer
You need to add below code of file app\design\frontend\Your-Theme\Your-Package\template\persistent\customer\form\login.phtml
Then you need to override function _loginPostRedirect of Mage_Customer_AccountController class