我正在創建一個模塊,在客戶成功登錄後檢查一些條件,如果條件爲真,則客戶登錄,否則不會。客戶成功登錄後執行某些操作:Magento
我知道這樣做的方法有兩種:
- 重寫
AccountController
- 隨着Magento的事件。
我的查詢是:
- 這是最好的辦法嗎?
- 有什麼事情可以滿足我的要求嗎?
或者如果還有其他最好的方法,請推薦。
我正在創建一個模塊,在客戶成功登錄後檢查一些條件,如果條件爲真,則客戶登錄,否則不會。客戶成功登錄後執行某些操作:Magento
我知道這樣做的方法有兩種:
AccountController
我的查詢是:
或者如果還有其他最好的方法,請推薦。
您需要使用customer_login
在Mage_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()
該事件,所以只要客戶成功登錄,您的觀察員的方法就會執行。 您可以在此處檢查您的條件是否符合要求。
我認爲如果可能的話使用magento事件的最佳方式。但在你的情況下,你必須檢查客戶登錄前的情況是否正確?如果是這樣,我不認爲有任何事件發生。所以最好的辦法是重寫控制器。
我想他想在客戶成功登錄後檢查一些條件。問題是這樣的 –
我也是這麼認爲,但如果你看到「如果條件是真的,那麼客戶登錄否則不是。」然後,應在客戶登錄之前檢查條件。 – aton1004
我想檢查客戶成功登錄 –
您能否向我解釋「customerLogin」如何工作 –
謝謝@Manashvi –