Shopware 5 - 删除文章时在后端使用哪个事件

问题描述

我想知道删除文章时 Shopware 5 后端使用了哪个事件,我在浏览器的网络选项卡中看到 controller ArticleList 方法 deleteProduct调用

enter image description here

正如它所说的,一个“后端模块产品商店的事件监听函数

所以我的问题是,我正在制作一个自定义插件,当文章删除时,我必须添加一些更多的逻辑。

我可以使用任何事件或钩子吗?

解决方法

您可以为此使用 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
    }
}