Magento, how to disable the module programmatically?

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

So, my module listens for it, and then does the following:

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

But the selected module is still active on every page.

I also tried this approach (the same, but in a different way):

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

Also, I tried reinstalling the config in the end and loading the Modules again, but both will not help.

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

Is it possible to programmatically disable the module?

Update 1 . This solution is great for working with sources. active = false really disables the module, but I also need it for the interface. Therefore, I continue to search.

Update 2 There are two methods in the /Mage.php application: init and initSpecified, which allows you to run Magento with only a selected number of modules. But these methods are not called in the thread by default.

Update 3 There is an observer event that we can use to activate or deactivate payment modules on the fly. It is called payment_method_is_active. In this code example, the check transfer payment method is not active:

 public function payment_method_is_active(Varien_Event_Observer $observer) { if($observer->getMethodInstance()->getCode()=='checkmo') { $observer->getResult()->isAvailable=false; } } 
+6
source share
2 answers

I think it depends on which module you want to disable. My article worked on the module that I wanted to disable, but this module double-checked whether it was activated, while most modules do not.

Magento downloads the entire module configuration at the same time. It is not possible to create a module that will listen to this process because the module would not be loaded during the process. This creates a paradox. It cannot be prevented from loading a module using another module.

As a result, only the following options remain:

  • Edit the kernel.
  • Use modules that are better designed and explicitly allow themselves to be disabled using the option or configuration method.
  • Change / expand the module you want to disable so that you can disable its functionality at runtime.

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

+4
source
+3
source

Source: https://habr.com/ru/post/891635/


All Articles