Magento - 2 个或更多观察者关注同一事件
我的 2 个观察者正在观察相同的 sales_order_shipment_save_before
事件。 ModuleA
是我首先创建的,然后我创建了 ModuleB
现在只有 ModuleB
的观察者被调用,而不是 ModuleA
>。
请让我知道我该如何解决这个问题,并且两位观察员都被召集了。
ModuleA
<?xml version="1.0"?>
<config>
<global>
<models>
<shipmentsave>
<class>My_Shipmentsave_Model</class>
</shipmentsave>
</models>
</global>
<adminhtml>
<events>
<sales_order_shipment_save_before>
<observers>
<shipmentsave>
<type>singleton</type>
<class>shipmentsave/observer</class>
<method>salesOrderShipmentSaveBefore</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_before>
</events>
</adminhtml>
</config>
Observer.php
<?php
class My_Shipmentsave_Model_Observer
{
public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
return;
}
}
ModuleB
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<My_Bshipment>
<version>0.1.0</version>
</My_Bshipment>
</modules>
<admin>
<routers>
<bshipment>
<use>admin</use>
<args>
<module>My_Bshipment</module>
<frontName>bshipment</frontName>
</args>
</bshipment>
</routers>
</admin>
<adminhtml>
<events>
<sales_order_shipment_save_before>
<observers>
<shipmentsave>
<type>singleton</type>
<class>bshipment/observer</class>
<method>salesOrderShipmentSaveBefore</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_before>
</events>
</adminhtml>
<global>
<models>
<bshipment>
<class>My_Bshipment_Model</class>
</bshipment>
</models>
<resources>
<bshipment_setup>
<setup>
<module>My_Bshipment</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</bshipment_setup>
<bshipment_write>
<connection>
<use>core_write</use>
</connection>
</bshipment_write>
<bshipment_read>
<connection>
<use>core_read</use>
</connection>
</bshipment_read>
</resources>
<blocks>
<!-- adminhtml>
<rewrite>
<shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</shipment_view>
</rewrite>
</adminhtml-->
<adminhtml>
<rewrite>
<sales_order_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</sales_order_shipment_view>
</rewrite>
<rewrite>
<sales_shipment_grid>My_Bshipment_Block_Adminhtml_Shipment_Grid</sales_shipment_grid>
</rewrite>
</adminhtml>
<!-- udropship>
<rewrite>
<adminhtml_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</adminhtml_shipment_view>
</rewrite>
</udropship-->
</blocks>
<helpers>
<bshipment>
<class>My_Bshipment_Helper</class>
</bshipment>
</helpers>
</global>
</config>
Observer.php
<?php
class My_Bshipment_Model_Observer
{
public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
return;
}
}
问候, 索拉布
2 of my observer are observing same sales_order_shipment_save_before
event. ModuleA
was the one i created first and then i created ModuleB
Now only ModuleB
's observer is called and not ModuleA
.
Please let me know how can i resolve this and both of observers are called.
ModuleA
<?xml version="1.0"?>
<config>
<global>
<models>
<shipmentsave>
<class>My_Shipmentsave_Model</class>
</shipmentsave>
</models>
</global>
<adminhtml>
<events>
<sales_order_shipment_save_before>
<observers>
<shipmentsave>
<type>singleton</type>
<class>shipmentsave/observer</class>
<method>salesOrderShipmentSaveBefore</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_before>
</events>
</adminhtml>
</config>
Observer.php
<?php
class My_Shipmentsave_Model_Observer
{
public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
return;
}
}
ModuleB
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<My_Bshipment>
<version>0.1.0</version>
</My_Bshipment>
</modules>
<admin>
<routers>
<bshipment>
<use>admin</use>
<args>
<module>My_Bshipment</module>
<frontName>bshipment</frontName>
</args>
</bshipment>
</routers>
</admin>
<adminhtml>
<events>
<sales_order_shipment_save_before>
<observers>
<shipmentsave>
<type>singleton</type>
<class>bshipment/observer</class>
<method>salesOrderShipmentSaveBefore</method>
</shipmentsave>
</observers>
</sales_order_shipment_save_before>
</events>
</adminhtml>
<global>
<models>
<bshipment>
<class>My_Bshipment_Model</class>
</bshipment>
</models>
<resources>
<bshipment_setup>
<setup>
<module>My_Bshipment</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</bshipment_setup>
<bshipment_write>
<connection>
<use>core_write</use>
</connection>
</bshipment_write>
<bshipment_read>
<connection>
<use>core_read</use>
</connection>
</bshipment_read>
</resources>
<blocks>
<!-- adminhtml>
<rewrite>
<shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</shipment_view>
</rewrite>
</adminhtml-->
<adminhtml>
<rewrite>
<sales_order_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</sales_order_shipment_view>
</rewrite>
<rewrite>
<sales_shipment_grid>My_Bshipment_Block_Adminhtml_Shipment_Grid</sales_shipment_grid>
</rewrite>
</adminhtml>
<!-- udropship>
<rewrite>
<adminhtml_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</adminhtml_shipment_view>
</rewrite>
</udropship-->
</blocks>
<helpers>
<bshipment>
<class>My_Bshipment_Helper</class>
</bshipment>
</helpers>
</global>
</config>
Observer.php
<?php
class My_Bshipment_Model_Observer
{
public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
return;
}
}
Regards,
Saurabh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有时间对此进行测试,但乍一看我会尝试使
每个模块变得不同。类似
和
No time to test this, but at first glance I'd try making
distinct for each module. Something like
and
每个观察者都应该有一个唯一的名字。
在代码中,两个观察者具有相同的名称。
因此,为每个观察者指定唯一的名称。
Each observer should have a unique name.
In the code both observer have the same name.
So give unique name to each observer.
我认为你错过了一些东西。您可以使用事件的观察者来调用尽可能多的函数。但对于每个事件,观察者的方法名称及其 ID 都应该不同。
您可以在 XML 中看到 id
shipmentsave
和方法salesOrderShipmentSaveBefore
是相同的。只要改变这个就可以了。
I think you are missing something. You can call as many functions as you can using observers for an event. But for each event, the observer's method name should be different, as well as its id.
You can see in the XML that the id
shipmentsave
and methodsalesOrderShipmentSaveBefore
is the same.Just change this and you are all done.