开发者

Magento, how to disable module programmatically?

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开发者_StackOverflow社区, 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;
    }
}


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.


Here is one solution I found.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜