如何在给定事件上调用 $customer->save()

发布于 2024-10-16 20:41:41 字数 563 浏览 1 评论 0原文

因此,我的任务是创建一个模块,根据来自另一个系统的现有身份验证数据在 Magento 中登录/注册客户。我现在的想法是创建一个可以由管理员通过链接放置的小部件。这部分我已经弄清楚该怎么做了。

下一部分是我可能需要一些帮助的地方。我已经阅读了足够多的文章来了解如何创建自定义 URL 结构以触发我的模块的操作,因此我假设我可以直接链接到我的操作,调用登录或注册请求并将用户发送回推荐页面(或他们的个人资料页面,我还没有完整地指定该项目,所以像这样的细节待定)。

这是我需要帮助的地方。我找到了通过登录和注册页面捕获 POST 请求的方法 - 我是否应该简单地扩展 Mage_Customer_AccountController 类并创建与 loginPostAction() 和 createPostAction() 方法中使用的调用大致相似的所需方法?

作为参考,我刚刚在新发布的 1.5.0.0 的全新安装上开始了一些初始项目开发 我所指的文件是

/magento/app/code/core/Mage/Customer/controllers/AccountController.php

So I've been tasked with creating a module to login/register a customer in Magento based on existing authentication data from another system. My thought for now is to create a Widget that can be placed by the admin with links. That part I've figured out how to do.

The next part is where I may need some assistance. I've read enough articles to understand how to create a custom URL structure in order to fire my Module's actions, so I assume I can link directly to my action, invoke a login or registration request and send the user back to the referral page (or their profile page, I haven't spec'd the project fully so details like this are TBD).

Here's where I need some help. I've found the methods that capture the POST request by the login and registration pages -- should I simply extend the Mage_Customer_AccountController class and create my required methods loosely similar to the calls used in loginPostAction() and createPostAction() methods?

For reference, I just started some initial project dev on a fresh install of the newly-released 1.5.0.0
The file I'm referring to is

/magento/app/code/core/Mage/Customer/controllers/AccountController.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2024-10-23 20:41:41

Magento 中所有基于事件的行为都应在事件/观察者方法中处理(更多信息可以在这里找到)....例如,在客户登录时调用您自己的操作将订阅 customer_login 或 customer_logout 事件。如果您尝试订阅管理区域中的客户保存事件,则该事件将是 adminhtml_customer_save_after 事件。 1.4.2 的完整列表可以此处找到。

另一个警告是——控制器过载是我会谨慎做的事情。您尝试做的大部分事情都可以通过创建自己的控制器并在提前获得功能后使用 Zend forward() 方法转发到所需的控制器方法(您在 Mage_Customer_AccountController 中提到过 loginPostAction() )来完成。

All event-based behavior in Magento should be handled within the event/observer methods (more information can be found here).... for instance to call your own actions on a customer login would subscribe to the customer_login or customer_logout events. If you are trying to subscribe to an event on customer save in the admin area it would be the adminhtml_customer_save_after event. A full list of these for 1.4.2 can be found here.

Another word of caution - overloading controllers is something I would do sparingly. Most of what you're trying to do can be accomplished by making your own controllers and using the Zend forward() method to forward to your desired controller method (you mentioned loginPostAction() in Mage_Customer_AccountController) after getting your functionality in ahead of time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文