我应该在 Magento 中使用哪些事件?
我想根据某些条件在添加新产品时发送邮件。
我应该将代码放在哪里,以便在保存产品时我可以:
- 获取它及其属性以使用
- 向某些客户发送电子邮件
提前致谢。
I want to send a mail when a new product is added depending on some criteria.
Where should I put my code so when a product is saved I can:
- Get it and its attribute to work with
- Send an email to some customer
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Magento 已在 Mage_ProductAlert 功能中包含此功能。您可以扩展该模块以考虑您的额外标准。它挂钩到 cron 系统,而不是同步调用观察者,这是一个更好的性能模型。
Magento already includes this functionality in the Mage_ProductAlert functionality. You could extend that module to take consideration of your extra criteria. It hooks into the cron system rather than a synchronous call to an Observer which is a much better performance model.
您可能想要查看catalog_product_new_action。从未使用过它,但它可能对你有用。不确定它是否适用于复制产品。我使用了另一个事件
catalog_product_save_beforeCatalog_product_before_save,该事件在保存产品时触发。 (使用 google 搜索 magento 事件备忘单)。但是通过两者,您都可以在观察者函数中获取产品,然后您可以从产品中获取属性。
其中 my_attribute 是您要查找的属性。
使用 php 的 mail() 函数发送电子邮件应该足够简单。如果你想让一切变得复杂,你可以使用 Magento 的发送交易电子邮件的方式,但你可能不需要它,除非你需要它可翻译等。
You might want to checkout catalog_product_new_action. Never used it, but it might work for you. Not sure if it works on duplicating a product. I have used another event,
catalog_product_save_beforecatalog_product_before_save, which is fired anytime a product is saved. (use google to search for magento event cheat sheets). But with both you can get the product in your observer function withThen you can get the attribute from the product.
where my_attribute is the attribute you are after.
Sending the email should be simple enough with php's mail() function. If you want to get all complicated you can use Magento's way of sending transactional emails, but likely you won't need that unless you need it to translatable, etc.