客户成功登录后执行一些操作:Magento
Perform Some Action after Customer successful Login : Magento
我正在创建一个模块,我想在其中检查客户成功登录后的某些条件,如果条件为真,则客户登录,否则不会。
我知道两种方法:
- 覆盖
AccountController
- 使用 Magento 事件。
我的查询是:
- 哪种方法最好?
- 有什么活动可以满足我的要求吗?
或者如果有其他最好的方法,请推荐。
我认为最好的方法是尽可能使用 magento 事件。但是在您的情况下,您必须在客户登录之前检查条件,对吗?如果是这样,我认为 that.So 没有任何事件,最好的方法是覆盖控制器。
您需要使用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()
,因此只要客户登录,您的观察者方法就会执行成功登录。
在这里您可以根据要求查看您的条件。
我正在创建一个模块,我想在其中检查客户成功登录后的某些条件,如果条件为真,则客户登录,否则不会。
我知道两种方法:
- 覆盖
AccountController
- 使用 Magento 事件。
我的查询是:
- 哪种方法最好?
- 有什么活动可以满足我的要求吗?
或者如果有其他最好的方法,请推荐。
我认为最好的方法是尽可能使用 magento 事件。但是在您的情况下,您必须在客户登录之前检查条件,对吗?如果是这样,我认为 that.So 没有任何事件,最好的方法是覆盖控制器。
您需要使用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()
,因此只要客户登录,您的观察者方法就会执行成功登录。
在这里您可以根据要求查看您的条件。