Magento - redirect user group after login

2019-09-15 06:22发布

问题:

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.

回答1:

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.



回答2:

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());


回答3:

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.



回答4:

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



标签: magento