Given a plugin defined in di.xml such as the following:

<type name="\Magento\Catalog\Model\Product">
    <plugin name="se_catalog_product_plugin_ample"
            disabled="false" />

How can I disable this defined plugin programatically (so not via di.xml but in code)? So when Magento comes round to processing the se_catalog_product_plugin_ample plugin, it is disabled, as if the node above had disabled="true".

I need to be able to alter this plugin programatically due to the requirement of reacting to store config differing in seperate store views in use in the environment. This config can't be reacted upon in di.xml (as far as I know).

Not sure if this is even possible. I know it would be possible to add logic inside the plugin to just $proceed() based on whatever condition needed, but this is one module wanting to disable another that I don't want to have tightly coupled. i.e. the module Example_Foo wants to disable a plugin in Example_Module.


In your di.xml you can do the following:

<type name="\Magento\Catalog\Model\Product">
    <plugin name="se_catalog_product_plugin_ample" disabled="true" />

Magento does it out of the box in Magento/Backend/etc/adminhtml/di.xml with the following :

<type name="Magento\Framework\App\Action\Action">
    <plugin name="storeCheck" disabled="true" />

Side note: you may have to make your module depends on the Example\Module ;)

  • Thanks for your answer Raphael, appeciate it. I need to be able to do this programatically though, rather than altering the disabled attribute in the di.xml of the other module from the disabler module. I'm going to need to disable the plugin based on system config differing per store. Your answer is actually what I'm doing right now in the wild and does work, but it's a stop gap as in the future I'll need the programatic approach. – Josh Davenport Nov 17 '16 at 17:25
  • Useful tip: you can check all possible plugin XML attributes in XSD schema: github.com/magento/magento2/blob/… – Roman Snitko May 8 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.