Magento - redirect user group after login
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.
T开发者_如何学JAVAhanks a lot.
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());
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.
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.
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
精彩评论