Shopware 5的活动优先级

发布于 2025-02-02 17:16:06 字数 942 浏览 4 评论 0原文

我有2个插件都使用相同的事件inlight_controller_action_postdispatchsecure_frontend_checkout 在插件A中,我可以将一个变量刺激到Smarty上,并且需要该变量为我的其他插件。 但是插件B在插件A之前运行。因此,我设置了优先级并用var_dump();





插件A:

 public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 1)
    ];
}
public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin A");
    }

插件B:

public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 2)
    ];
}
    public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin B");
    }

现在,当我运行它时,输出为:

plugin B, Plugin A

但是插件A必须首先运行,我在做什么错?谢谢

i have 2 plugins both use same event Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout
in plugin A i assing a variable to smarty and need that variable for my other plugin.
but plugin B runs before plugin A. so i set priorities and tested it with a var_dump();

Plugin A:

 public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 1)
    ];
}
public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin A");
    }

Plugin B:

public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 2)
    ];
}
    public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin B");
    }

now when I run it, the output is:

plugin B, Plugin A

but plugin A must run first, what am I doing wrong ? Thanks

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

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

发布评论

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

评论(2

奢欲 2025-02-09 17:16:06

数字越高,执行订户越早。因此,您必须更改优先级。

插件A:

 public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 2)
    ];
}
public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin A");
    }

插件B:

public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 1)
    ];
}
    public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin B");
    }

The higher the number, the earlier a subscriber is executed. So you have to change the priorities.

Plugin A:

 public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 2)
    ];
}
public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin A");
    }

Plugin B:

public static function getSubscribedEvents()
{
    return [
        'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => array('onCheckout', 1)
    ];
}
    public function onPostDispatchCheckout(\Enlight_Event_EventArgs $args)
    {
        var_dump("Plugin B");
    }
爱本泡沫多脆弱 2025-02-09 17:16:06

正如Pawel提到的那样,您可以在事件订阅中设置优先级。有两个语法要做此

事件=> [subscriber =>优先级]

'inlight_controller_action_postdispatchsecure_frontend_checkout'=> ['onCheckout'=> 1]

事件=> [subscriber,Priority]

'imlight_controller_action_postdispatchsecure_frontend_checkout'=> ['onCheckout',1]

据我所知,它就像z索引一样,较高的胜利。您可能需要重新安装插件并清除缓存。

As Pawel mentioned you can set the priority in the event subscription. There are two syntaxes to do this

event => [subscriber => priority]

'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => ['onCheckout' => 1]

or

event => [subscriber, priority]

'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => ['onCheckout', 1]

As far as I know its like z-index, the higher one wins. And you might need to reinstall the plugin and clear the cache.

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