cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite or plug in to observer method

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Overwrite or plug in to observer method

I am wondering if and how it is possible to either overwrite or plug in to an observer method?

I tried to set a preference in /etc/frontend/di.xml:

<preference for="Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver"
                type="Vendor\Module\Observer\Frontend\Quote\Address\CollectTotalsObserver"/>

If I add a logging to the original class and to my custom one, I can see that still the original class is executed, but not my overwritten one.

I then tried to add code with a plugin in same di.xml:

<type name="Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver">
        <plugin disabled="false" name="Vendor_Module_Plugin_Magento_Quote_Observer_Frontend_Quote_Address_CollectTotalsObserver" sortOrder="10"
                type="Vendor\Module\Plugin\Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver"/>
    </type>

But still no logging output. Of course I cleared cache, run setup:upgrade and setup:di:compile, but it just does not work. I am sure that all files are in the correct place and classes named correctly.

Can someone explain this or give me any hint?