产品删除观察者
我想为产品删除创建一个观察者。意味着当管理员删除产品时,在删除过程中我想在此过程中添加一些自定义功能。目前我正在用于
catalog_controller_product_delete
此目的。但它对我没有任何作用。请帮我。在产品删除过程中如何做一些额外的事情?
我想将已删除的产品 ID 发送到我的 API,其中我有该产品的副本,以便我也可以从那里删除它,但它不会触发该事件。我知道这一点是因为我通过
触发 sendProductDelReq() 方法,并且为了进行验证,我在该方法中放置了一个骰子。
I want to create an observer for Product deletion. Means when admin deletes a product, during deletion I want to add some custom functionality in this process. Currently I'm using
catalog_controller_product_delete
for this purpose. But it is doing nothing for me. Please help me. How can I do something extra during product deletion?
I want to send deleted product id to my API where I have copy of this product so that I can delete it from there too, but it is not triggering the event. I know this because I am triggering sendProductDelReq() method by <method>sendProductDelReq</method>
and for verification I've put a die in this method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于遇到同样问题并希望在这里找到答案的人。
我发现了问题。
首先,您如何删除该产品?
如果您从产品编辑页面中删除产品,您的观察者很可能将无法工作。
如果您从“产品网格”页面中删除产品,您的观察器可能会正常工作。
问题在于,事件:catalog_controller_product_delete,仅在 productController() 的 massDeleteAction() 中分派。
并且 >不在deleteAction()内。
我已将此问题作为错误提交到 magentocommerce.com/bug-tracking。
要解决此问题,请粘贴以下内容:
在 deleteAction() 内,位于
$product->delete();
之前像这样:
For the people that have encountered the same problem and who were hoping to find an answer here.
I found the problem.
First of all, how are you deleting the product?
If you are deleting the product from within the product edit page, chances are your observer won't work.
If you are deleting the product from within the Product Grid page, your observer will probably work fine.
The issue is that the event: catalog_controller_product_delete, only gets dispatched in the massDeleteAction() in the productController().
And NOT inside the deleteAction().
I've already submitted this issue as a bug at magentocommerce.com/bug-tracking.
To fix this, paste this:
Inside your deleteAction(), right before
$product->delete();
Like so:
今天搜索了一些类似的问题后,由于这个拉取请求。
您可以使用 catalog_product_delete_before 事件,该事件在 Mage_Core_Model_Abstract::_beforeDelete() 中调度。适用于网格和编辑页面中的单独删除。
此事件未显示在 Magento 事件列表 创建使用
After searching a bit for a similar issue today I found another event for delete thanks to this pull request.
You can use catalog_product_delete_before event, which is dispatched in Mage_Core_Model_Abstract::_beforeDelete(). Works for individual deletes in both grid and edit page.
This event is not shown on the Magento event list created using
您实际上应该使用
catalog_product_delete_before
和catalog_product_delete_after
事件。更多信息请点击这里https://stackoverflow.com/a/14211286/515268
You should actually be using the
catalog_product_delete_before
andcatalog_product_delete_after
events.More on it here https://stackoverflow.com/a/14211286/515268
我猜catalog_product_delete_after_done是正确的事件
Mage_Catalog_Model_Product具有以下dispatchEvent:
否则,您可能会遇到产品在Magento中被删除但不在您的API中的情况
I guess catalog_product_delete_after_done is the proper Event
Mage_Catalog_Model_Product has the following dispatchEvent:
Otherwise, you could get the case that the product is deleted in Magento but not in your API
您还可以使用
无需修改任何核心文件。
以下是删除后函数调度 model_delete_after 事件的简要说明。
You can also use
without modifying any core file.
Here's a brief of the after delete function dispatching the model_delete_after event.