Magento: 自定义用户登录导向页面 Redirect Customer to Previous Page After Login

Configuration Settings

 

– Login to admin panel
– Go to System -> Configuration -> CUSTOMERS -> Customer Configuration -> Login Options
– Set: Redirect Customers to Account Dashboard after Loggin in = No
– You can see in comments for this field: Customer will stay on the current page if “No” is selected.

 

This setting will redirect customers to the page from where they have come to login page. This setting is applicable for all pages of your Magento website.

 

You might have another condition of having this feature only on some specific pages. For example, you might want this feature only on product view page. Or, you might have a category that is visible to logged in customers only. In this case, you can simply use the following code:

 

Redirect to customer login page

if(!Mage::helper('customer')->isLoggedIn()) {
	Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl()); 
	//$this->_redirect('customer/account/login');
	exit('<h2>Redirect to login page ... </h2><script>location="/customer/account/login/"</script>');
}

 

Show a login link for non-logged in customers

if(!Mage::helper('customer')->isLoggedIn()) {
Mage::getSingleton('customer/session')
            ->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());
echo '<p>Please <a href="'.Mage::getUrl('customer/account/login').'">Login</a> to view the page.</p>';
}

Customers will be redirected to previous page after successful login.

 

Hope it helps. Thanks.

 

原文:http://blog.chapagain.com.np/magento-redirect-customer-to-previous-page-after-login/

 

根据此原理,我们也可以修改成为url参数的形式。

// http://yourdomain.com/customer/account/login/?redirect=http://redirecturi.com
if(!Mage::helper('customer')->isLoggedIn()) {
	Mage::getSingleton('customer/session')->setBeforeAuthUrl(isset($_GET['redirect']) ? $_GET['redirect'] : ''); 
	//$this->_redirect('customer/account/login');
	exit('<h2>Redirect to login page ... </h2><script>location="/customer/account/login/"</script>');
}

 

 

 

原文/转自: Magento: 自定义用户登录导向页面 Redirect Customer to Previous Page After Login

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值