因此,在登录期间,我想检查用户是否在特定客户群中,如果检查失败则阻止登录。
我扩展了AccountController,并加入了快速检查:
$customer = Mage::getModel('customer/customer')->loadByEmail($login['username']);
if ($customer->getGroupId() != 2) {
$msg = Mage::getSingleton('core/session')->addError($this->__('You must have a wholesale account to access this area.'));
header('Location: '. Mage::getUrl('customer/account/login'));
exit;
}
但是,运行此命令会返回会话错误消息,“使用网站范围时必须指定客户网站ID”。
基本上,我只需要获取尝试登录的用户的组ID,我想我可以通过客户模型loadByEmail()中提供的方法来获取它。但是,是的,星期五,显然MageLords希望我迟到。
我已经尝试了许多方法来实现这一点,包括允许登录,然后检查ID,然后执行$ session-> logout()如果检查失败,但这阻止了我显示会话错误消息,因为logout()方法正在清除所有会话消息(包括'core / session')。
有什么想法吗?
答案 0 :(得分:7)
在使用website_id
方法之前,您应该设置loadByEmail
。我知道,这似乎很奇怪,但这是由customer
可能是网站范围的实体这一事实所决定的。因此,如果loadByEmail
模型未分配给任何网站,customer
方法将抛出异常。
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($login['username']);