Here’s a bit of code I used while developing a custom module for a client’s shop. The module allows a Flash application to launch popups of any given product. There was a module the client definitely wanted to keep but that was interfering with my ability to close the popup when the client clicked the ‘Add to Cart’ button – and we didn’t need that module working within the popup iframe. I googled for a while but there was no documentation on how to do this.

So here’s what I did to disable that module and its output. It might not be the best solution but it worked nicely and I didn’t have to manually remove each item in my module’s layout file:

  1. I already had a controller, so I added the following protected function:
    protected function _disableModule($moduleName) {
        // Disable the module itself
        $nodePath = "modules/$moduleName/active";
        if (Mage::helper('core/data')->isModuleEnabled($moduleName)) {
            Mage::getConfig()->setNode($nodePath, 'false', true);
        }
    
        // Disable its output as well (which was already loaded)
        $outputPath = "advanced/modules_disable_output/$moduleName";
        if (!Mage::getStoreConfig($outputPath)) {
            Mage::app()->getStore()->setConfig($outputPath, true);
        }
    }
    
  2. and called it in my action before loading the layout: $this->_disableModule('Namespace_Modulename');

A better solution might be to hook at an earlier moment, preferably before module layouts are loaded, but I didn’t have enough time to research on that possibility.

If you know of a better way to do this please let us know!

2 Comments Disabling a Module and its Output Programmatically

  1. Sameer

    Thanks for sharing this. I had setup a store and was trying to disable few modules output and ultimately crashed my admin. Is it possible to pragmatically enable the output of all the installed modules? because I cant not any option to enable them again. Thank You

    Reply
    1. Gabriel Somoza

      Hi Sameer. I believe the best (quickest) way to do that is to simply log-in to your database and run the following command:

      UPDATE core_config_data SET value = 0 WHERE path LIKE 'advanced/modules_disable_output/%';

      Reply

Leave a Reply