6

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;
    }
}
1
  • i don't see a place where you perform "save" on this one as this value is stored in module file not in database you have to change the value in config file and then save this or else this will be reset all the time Commented Jun 29, 2011 at 14:41

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Gabriel, very helpful reply. My goal was to develop the module, which'll allow to disable any module and show them only for the developer IPs. I don't want to override the core this time :)
I understand. Trying to entirely disable any module using another module can't be done because all modules are loaded at the same time before any events are fired.
2

Here is one solution I found.

3 Comments

He uses the same approach, active=false, the most powerful disabler is not working. The output disable works, but this approach could not be used with all modules. Anyway, thanks!
Could you please share the useful contents of the link here? Links have a tendency to disappear.
Link not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.