Magento 验证后注销客户表单观察者并添加错误消息
我是一个magento新手,我有两个登录表单,一个是普通客户,另一个是“批发”类型的客户,所以我创建了一个观察者,在其中我检查用户(试图登录的用户)是否是批发客户,然后将其注销Magento 验证后注销客户表单观察者并添加错误消息,magento,Magento,我是一个magento新手,我有两个登录表单,一个是普通客户,另一个是“批发”类型的客户,所以我创建了一个观察者,在其中我检查用户(试图登录的用户)是否是批发客户,然后将其注销 class Hs_Login_Model_Observer { public function validateCustomer($observer){ $c= $observer->getCustomer(); $customer = Mage::getModel('cu
class Hs_Login_Model_Observer {
public function validateCustomer($observer){
$c= $observer->getCustomer();
$customer = Mage::getModel('customer/customer')->load($c->getId() );
$customerType = Mage::getSingleton('customer/group')->load($c->getId())->getData('customer_group_code');
if ( $customerType == "Wholesale") {
Mage::getSingleton('customer/session')->logout();
}
}
}
它可以工作,但我还想在登录页面上显示错误消息
我试过布局手柄
$observer->getEvent()->getLayout()->getUpdate()
->addHandle('cus_layout handle')
我试过了
Mage::getSingleton(‘core/session’)->addError(‘Error message’);
但是似乎没有什么工作,需要帮助通知路径是正确的 唯一的问题是,链接到客户帐户的页面不会显示
core/session
消息,而是显示customer/session
消息
因此,这应该是可行的:
Mage::getSingleton('customer/session')
->addError(
Mage::helper('customer')
->__('An error occurred')
);
// also useful to remember to make messages translatable via an helper
我发现的一个特别的解决方案是根本不使用观察者, 我只想跟踪一下,如果“批发商客户”在默认登录页面上渴望,那么磁电机应该给出一些错误 所以我重写了AccountController.php
class Hs_Login_AccountController extends Mage_Customer_AccountController {
public function loginPostAction() {
.
.
.
.
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
$regularCustomer;
if ($login['form_type'] == "default") {
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->loadByEmail($login['username']);
$customerType = Mage::getSingleton('customer/group')->load($customer->getId())->getData('customer_group_code');
if ($customerType == "Wholesale") {
$session->addError($this->__('invalid username and password'));
$this->_loginPostRedirect();
return;
}
.
.
.
.
}
}
}
}
这是通过配置Magnet来运行我的类来控制此路由来完成的
<frontend>
<routers>
<customer>
<args>
<modules>
<Hs_Login before="Mage_Customer">Hs_Login</Hs_Login>
</modules>
</args>
</customer>
</routers>
</frontend>
Hs_登录
并以常规登录页面的形式设置隐藏属性
<li>
<div class="hidden">
<input type="text" name="login[form_type]" value="default" />
</div>
</li>
您再次在客户会话中添加错误,当我注销客户时,会话会随着其消息一起被删除,因此仍然存在相同的问题。处理消息的会话机制与您是否有客户登录这一事实无关,因此这不是问题的原因。当您定义两个表单以将它们连接到正确的会话存储以显示消息时,可能实际上忘记了一些事情。这里需要更多关于您使用的表单和控制器的上下文。我发现这有点走错了方向,我重写了AccountController的post操作,还更新了form.phtml文件,以便找到哪个客户从哪个表单登录