1

I have two themes e.g. mobile and desktop.
For mobile theme I have separated the first step of the checkout process i.e. Login step to different page.
Like
page no.1-from basket page a person goto the login page(login or checkout as guest).
So here the file present in "chekout/onepage/login.phtml" is getting rendered.

page no.2-The next step is to calculate delivery method and delivery options in a page.
page no.3-Then the payment method page and finally the checkout process.

So I want when a person go to the page no. 1 (i.e. login page) and give the email and password and click the login button , then the person will redirected to the page no.2(delivery method and options).

But it Redirects to the account dashboard page.

Below is the code for the login and redirect which is located at ..
core/Mage/Customer/controller/AccountContorller.php

public function loginPostAction()
{
    if ($this->_getSession()->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session = $this->_getSession();

    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');
        if (!empty($login['username']) && !empty($login['password'])) {
            try {
                $session->login($login['username'], $login['password']);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);
                }
            } catch (Mage_Core_Exception $e) {
                switch ($e->getCode()) {
                    case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                        $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
                        $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                        break;
                    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                        $message = $e->getMessage();
                        break;
                    default:
                        $message = $e->getMessage();
                }
                $session->addError($message);
                $session->setUsername($login['username']);
            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
            }
        } else {
            $session->addError($this->__('Login and password are required.'));
        }
    }

    $this->_loginPostRedirect();
}

/**
 * Define target URL and redirect customer after logging in
 */
protected function _loginPostRedirect()
{
    $session = $this->_getSession();

    if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {
        // Set default URL to redirect customer to
        $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
        // Redirect customer to the last page visited after logging in
        if ($session->isLoggedIn()) {echo "gone";exit;
            if (!Mage::getStoreConfigFlag(
                Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
            )) {
                $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                if ($referer) {
                    // Rebuild referer URL to handle the case when SID was changed
                    $referer = Mage::getModel('core/url')
                        ->getRebuiltUrl(Mage::helper('core')->urlDecode($referer));
                    if ($this->_isUrlInternal($referer)) {
                        $session->setBeforeAuthUrl($referer);
                    }
                }
            } else if ($session->getAfterAuthUrl()) {
                $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
            }
        } else {echo "go";exit;
            $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
        }
    } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) {
        $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl());
    } else {
        if (!$session->getAfterAuthUrl()) {
            $session->setAfterAuthUrl($session->getBeforeAuthUrl());
        }
        if ($session->isLoggedIn()) {
            $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
        }
    }

    $this->_redirectUrl($session->getBeforeAuthUrl(true));
}

How can I change the redirection to a particular page after login step for mobile theme only ?
Is it possible to redirect to different url for different theme in a single store from the same method ?
Or
Is it required to override the customer module ?
How can I override the redirect method of customer to redirect to particular page ?

  • see this post, you can use an observer after login event – Idham Choudry May 26 '17 at 1:52
0

go to persistent/customer/form/login.phtml or customer/form/login.phtml and add the following into the form:

<?php if (Mage::getDesign()->getTheme('frontend') == "your_mobile_theme"): ?>
    <input type="hidden" name="referer_url" value="your_page_url"/>
<?php endif; ?>

please let me know if it's ok

  • 1
    But the login form I am talking about is supposed to be present at..mypackage/iphone/template/checkout/onepage/login.phtml – Kishore Patra Jan 21 '16 at 6:59
0

You first need to set "Redirect Customer to Account Dashboard after Logging in" to "No" as shown in below screenshot.

enter image description here

And in the "checkout/onepage/login.phtml" change form action as mentioned below.

<form action="<?php echo $this->getUrl('customer/account/loginPost',array('referer' => Mage::helper('core')->urlEncode('page no.2 url'))) ?>" method="post">

Here you can do by another way.

write a basic custome module and register an event for customer_login in the frontend area as below

<frontend>
  <events>
    <customer_login>
        <observers>
            <your_module>
                <class>your_module/observer</class>
                <method>redirectLogin</method>
            </your_module>
        </observers>
    </customer_login>
</events>
</frontend>

After that, create an observer class and write below function.

public function redirectLoginLogin($observer)
{
  $session = Mage::getSingleton('customer/session');
  if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') ===   false)
  {       
    $session->setAfterAuthUrl('Your page 2 url');
  } 
  else 
  {
    $session->setAfterAuthUrl(Mage::helper('core/http')->getHttpReferer());
  }
  $session->setBeforeAuthUrl('');
}

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.