2015-06-12 48 views
1

我正在創建一個模塊,在客戶成功登錄後檢查一些條件,如果條件爲真,則客戶登錄,否則不會。客戶成功登錄後執行某些操作:Magento

我知道這樣做的方法有兩種:

  1. 重寫AccountController
  2. 隨着Magento的事件。

我的查詢是:

  1. 這是最好的辦法嗎?
  2. 有什麼事情可以滿足我的要求嗎?

或者如果還有其他最好的方法,請推薦。

回答

3

您需要使用customer_loginMage_Customer_Model_Session模型的方法setCustomerAsLoggedIn()事件customer_login分派。

config.xml中

<customer_login> 
    <observers> 
     <yourobservername> 
      <type>model</type> 
      <class>yourmodule/path_to_class</class> 
      <method>customerLogin</method> 
     </yourobservername> 
    </observers> 
</customer_login> 

和你的觀察

class YourCompany_YourModule_Model_Observer 
{ 
    public function customerLogin($observer) 
    { 
     $customer = $observer->getCustomer(); 
    } 
} 

每當用戶成功地登錄,事件customer_login將被解僱,你所觀察到的方法customerLogin()該事件,所以只要客戶成功登錄,您的觀察員的方法就會執行。 您可以在此處檢查您的條件是否符合要求。

+0

您能否向我解釋「customerLogin」如何工作 –

+0

謝謝@Manashvi –

0

我認爲如果可能的話使用magento事件的最佳方式。但在你的情況下,你必須檢查客戶登錄前的情況是否正確?如果是這樣,我不認爲有任何事件發生。所以最好的辦法是重寫控制器。

+0

我想他想在客戶成功登錄後檢查一些條件。問題是這樣的 –

+0

我也是這麼認爲,但如果你看到「如果條件是真的,那麼客戶登錄否則不是。」然後,應在客戶登錄之前檢查條件。 – aton1004

+0

我想檢查客戶成功登錄 –

相關問題