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;
}
}
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.
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:
Hope this helps.. let me know if I can help you find a way to disable the module you're dealing with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With