Magento - 2 or more observer on same event

前端 未结 3 2225
Happy的楠姐
Happy的楠姐 2021-02-14 16:50

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

相关标签:
3条回答
  • 2021-02-14 17:22

    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.

    <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>
    
    <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>
    

    You can see in the XML that the id shipmentsave and method salesOrderShipmentSaveBefore is the same.

    Just change this and you are all done.

    0 讨论(0)
  • 2021-02-14 17:23

    No time to test this, but at first glance I'd try making

    <shipmentsave>
    

    distinct for each module. Something like

        <observers>
          <shipmentsave>
            <type>singleton</type>
            <class>bshipment/observer</class>
            <method>salesOrderShipmentSaveBefore</method>
          </shipmentsave>
        </observers>
    

    and

        <observers>
          <bshipmentsave>
            <type>singleton</type>
            <class>bshipment/observer</class>
            <method>salesOrderShipmentSaveBefore</method>
          </bshipmentsave>
        </observers>
    
    0 讨论(0)
  • 2021-02-14 17:26

    Each observer should have a unique name. In the code both observer have the same name. So give unique name to each observer.

    0 讨论(0)
提交回复
热议问题