问题描述
我想知道删除文章时 Shopware 5 后端使用了哪个事件,我在浏览器的网络选项卡中看到 controller ArticleList 方法 deleteProduct 被调用
所以我的问题是,我正在制作一个自定义插件,当文章被删除时,我必须添加一些更多的逻辑。
我可以使用任何事件或钩子吗?
解决方法
您可以为此使用 doctirne 事件:https://developers.shopware.com/developers-guide/models/#remove-event
,我设法通过这种方式解决了我的问题,希望它在未来对某人有所帮助。
// subscribe to an event
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PostDispatchSecure_Backend_ArticleList' => 'onArticleListPostDispatch'
];
}
// add the logic to your subscribed method
public function onArticleListPostDispatch(\Enlight_Event_EventArgs $args)
{
$controller = $args->getSubject();
$request = $controller->Request();
if ($request->getActionName() == 'deleteProduct') {
// add your logic here
}
}