Shopware 5的活动优先级
我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数字越高,执行订户越早。因此,您必须更改优先级。
插件A:
插件B:
The higher the number, the earlier a subscriber is executed. So you have to change the priorities.
Plugin A:
Plugin B:
正如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.