Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento, how to disable module programmatically?

Tags:

module

magento

My goal is to disable the module programmatically (for example during some observer event). The earliest observer I found is controller_front_init_before.

So my module is listening to it, and then do the next:

Mage::getConfig()->getModuleConfig('IG_LightBox')->active=(string)'false';

But the selected module is still active on each page.

Also I tried this approach (the same but in different way):

Mage::getConfig()->getNode('modules/IG_LightBox')->active=(string)'false';

Also I tried to reinit config after all and to loadModules one more time, but both won't help.

Mage::getConfig()->loadModules(); // won't help
Mage::getConfig()->reinit(); // won't help

Is it possible to disable the module programmatically?

Update 1. This solution perfectly works for the back-end. active=false really disables the module, but I need it for the front-end too. So I keep my search.

Update 2 There are 2 methods in the app/Mage.php, called init and initSpecified, which allows to run the Magento with the selected number of modules only. But those methods are not called in the default flow.

Update 3 There is an observer event we can use for activating or deactivating the payment modules on the fly. It's called payment_method_is_active. This code example makes the check money order payment method being not active:

public function payment_method_is_active(Varien_Event_Observer $observer)
{
    if($observer->getMethodInstance()->getCode()=='checkmo')
    {
        $observer->getResult()->isAvailable=false;
    }
}
like image 252
Pavel Polyakov Avatar asked Jun 29 '11 12:06

Pavel Polyakov


People also ask

How do you completely disable a module in Magento?

Although the title might sound silly and so easy, there are lot of people having difficulties with this. At first turning Magento module can be easy as going trough System Configuration > Current Configuration Scope > Advanced > Advanced > Disable Module Output.


1 Answers

I think it depends on which kind of module you want to disable. My article worked for the kind of module I wanted to disable, but that module double-checked if it was activated, while most modules don't do that.

Magento loads all module configuration at once. Its impossible to create a module that will listen to this process because the module would have not been loaded while the process takes place. This creates a paradox. Its impossible to prevent a module from loading using another module.

As a result the only options you are left with are:

  1. Edit the core.
  2. Use modules which are better designed and explicitly allow themselves to be disabled through a config option or method.
  3. Edit/extend the module you want to disable so that you can disable its functionality during runtime.

Hope this helps.. let me know if I can help you find a way to disable the module you're dealing with.

like image 119
Gabriel Somoza Avatar answered Nov 15 '22 07:11

Gabriel Somoza