Magento - redirect user group after login

2019-09-15 05:56发布

How can I redirect different user groups to different pages in Magento ?

what I want to do is to assign a category to each customer group to redirect the user to it on login.

Thanks a lot.

标签: magento
4条回答
【Aperson】
2楼-- · 2019-09-15 06:18

How about this for an approach:

Consider starting with an existing module such as:

http://www.magentocommerce.com/magento-connect/MagePsycho/extension/3763/custom_login_redirect

Then adding your own logic. For the group name of a customer you can try this:

$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

$group = Mage::getModel ('customer/group')->load($groupId)->getCode();

If you then have your categories named as per your groups you can do a redirect to http:// + base_url + $group therfore removing the need to explicitly work out what category page to load.

查看更多
对你真心纯属浪费
3楼-- · 2019-09-15 06:22

In order to redirect the customer as per customer group, there is a commercial extension: http://www.magepsycho.com/custom-login-redirect-pro.html really worths trying. FYI many merchants are using this module for their magento sites.

Happy e-commerce!! Regards

查看更多
Juvenile、少年°
4楼-- · 2019-09-15 06:33

I have not tried this. I think you need to do the following on the customer_login event:

$session = Mage::getSingleton('customer/session');
$category = // A category object based on $session->getCustomerGroupId()
$session->setBeforeAuthUrl($category->getUrl());
查看更多
\"骚年 ilove
5楼-- · 2019-09-15 06:34

Go to /app/code/local/MagentoPycho/Customer/controllers/AccountController.php and replace this:

$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());

with this:

$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($groupId == 5) {
    $session->setBeforeAuthUrl('http://google.com');
} else {            
    // Set default URL to redirect customer to
    $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
}

Be sure to put your Group ID instead of the "5" and your redirect URL instead of google.com.

I just tried it.

查看更多
登录 后发表回答