验证后注销客户表单观察者并添加错误消息

时间:2016-02-03 10:20:25

标签: magento

我是一名magento新手,我有两个登录表格1给普通客户,1个给客户打字#34;批发"所以我创建了一个观察者,我在其中检查如果用户(试图登录)是批发客户,它会将其记录下来,就像

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

但似乎没有任何工作,需要帮​​助

2 个答案:

答案 0 :(得分:1)

通知路径是正确的。

唯一的问题是,链接到客户帐户的网页不会显示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

答案 1 :(得分:0)

我找到的一个特殊解决方案是根本不使用观察者, 我只是想跟踪一个"批发商客户"从默认登录页面向往,然后磁控应该给出一些错误,

所以我重写了AccountController.php

            tooltip: { shared: true,
        formatter: function() {
            var s = '<b>'+ this.x +'</b><br/>';                
            $.each(this.points, function(i, point) {
                s += '<span style="color:'+point.series.color+'">'+point.series.name+'</span>: <b>'+point.y+'</b><br/>'
                 s+='<br> Series2: ' + series2Data[i]  ;
            });

            return s;
        },
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }, {
    visible:false,
        data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5]
    }]

这是通过配置magneto来运行我的类来控制这条路线来完成的

    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;
                          }
                           .
                           .
                           .
                           .


                     }


              } 
        }
    }

并以常规登录页面的形式设置隐藏属性

<frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                         <Hs_Login before="Mage_Customer">Hs_Login</Hs_Login>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>