1

I am using Magento 1.9 on localhost with wamp. I am using an ajax login and register module which redirects to customer account. The login and register are on the homepage. I am trying to redirect to a custom cms page after login, or after registering. I've contacted the developper but so far no replies, so I thought I would try here.

The template file which is used for the homepage, for login forms and register forms looks like this:

<?php // If user is not logged in ?>
<?php if (Mage::helper('customer')->isLoggedIn() != true) : ?>

<div class="account-login">
<!-- login form here -->
</div>

<div class="account-register">
<!-- register form here -->
</div>

<?php /* else if the user is logged in */ 
else :

// redirect to http://127.0.0.1/website/landing-page/

endif; ?>

so far I've tried:

<?php /* else if the user is logged in */ 
else :
$url="http://127.0.0.1/website/landing-page";
$this->_redirectUrl($url);
endif; ?>

That gave me the following error in Magento:

Invalid method Youama_Ajaxlogin_Block_Ajaxlogin::_redirectUrl(Array
(
    [0] => http://127.0.0.1/website/landing-page
)
)

note: $this->_redirectUrl($url); and $this->_redirect($url); gave the same error message.

I tried another way:

$url="http://127.0.0.1/website/landing-page";
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();

That gave an error in Firefox saying that there is a redirect loop problem. Another try was:

$url="http://127.0.0.1/website/landing-page";
Mage::app()->getResponse()->setRedirect($url);

That also gave an error in Firefox saying that there is a redirect loop problem

I've read that there are ways to redirect to external links wich should specifically be used for that, and then other methods of redirecting. I believe I should edit the module controller to make the redirection work.

The ajax login module controller ( AccountController.php ) looks like this :

class Youama_Ajaxlogin_AccountController extends Mage_Customer_AccountController

{
    /**
     * @var string
     */
    protected $_url;

    /**
     * Before actions.
     * @return Mage_Core_Controller_Front_Action|void
     */
    public function preDispatch()
    {
        $this->_url = Mage::getBaseUrl() . '?yregister';

        parent::preDispatch();
    }

    /**
     * Disable login action.
     */
    public function loginAction()
    {
        $this->_setLocation();
    }

    /**
     * Disable create action.
     */
    public function createAction()
    {
        $this->_setLocation();
    }

    /**
     * Redirect to home.
     */
    protected function _setLocation()
    {
        Mage::app()->getFrontController()->getResponse()->setRedirect($this->_url);
    }
}

I believe I have to add or change some lines of code there in order to be able to use $this->_redirectUrl($url); or $this->_redirect($url);

Any help would really be appreciated at this point, I'd love to understand how this works.

  • Thanks to @Amit Bera and stackoverflow.com/questions/8769656/… : I had to put <?php if($this->helper('customer')->isLoggedIn()){ Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('landing-page')); } ?> outside the ajaxlogin.phtml template file of the module , it works in header.phtml for example. Not sure if that is the cleanest/best solution though. – Malcolm Dezign Aug 16 '14 at 12:28
  • Try this extension magecomp.com/magento-mobile-login.html – Gaurav Jain Apr 17 '17 at 16:24
3

Just change:

$url="http://127.0.0.1/website/landing-page";

to

$url=Mage::getUrl('landing-page');

if using then try

$this->_redirect($url)

to EDIT: First of all _redirect is not a block class function,it is a controller function.You need direction then used the code

$url=Mage::getUrl('landing-page');

Mage::app()->getFrontController()->getResponse()->setRedirect($url); 
exit();
  • Thank you but it does not work. The error message still says: "Invalid method Youama_Ajaxlogin_Block_Ajaxlogin::_redirect(Array ( [0] => 127.0.0.1/website/landing-page ) – Malcolm Dezign Aug 16 '14 at 8:35
  • 1
    are you put this code in block file...??? – Amit Bera Aug 16 '14 at 9:38
  • 1
    then put block file code... – Amit Bera Aug 16 '14 at 9:39
  • the .php file inside module Block folder is community/Youama/Block/Ajaxlogin.php and contains : class Youama_Ajaxlogin_Block_Ajaxlogin extends Mage_Core_Block_Template { /** * Retrieve string 1 if Redirection to profile is YES on system config page. * @return string */ public function isRedirectToProfile() { if (Mage::getStoreConfig('youamaajaxlogin/settings/redirection')) { return '1'; } return '0'; } } – Malcolm Dezign Aug 16 '14 at 11:40
  • from block you want to redirect to cms pahe?? – Amit Bera Aug 16 '14 at 12:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.