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.
Best Answer
Just change:
to
if using then try
to EDIT:
First of all _redirect is not a block class function,it is a controller function
.You need direction then used the code