Skip to main content
added 6 characters in body
Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

TheFrom the admin section with all the modules does notyou cannot disable thea module. From there you can olyonly disable the output of some module. This means that the code is still executed but notno output is generated.
Indeed, the way to disable a module is to change the tag <active> to false in the module declaration xml (app/etc/modules/Namespace_Module.xml) and clear the cache.
I don't think you can disable a module from code since the modules are loaded very early in the application (Mage_Core_Model_Config::_loadDeclaredModules()).
When building custom modules I also like to be able to disable them with 'one click'. Here is how I usually do it:

  • add in the system.xml an 'enabled' field.

    Module is enabled select adminhtml/system_config_source_yesno 1 1 1 1
  • create a method in the helper to check this flag

    public function getIsEnabled(){ return Mage::getStoreConfigFlag('section/group/enabled'); //replace section & group with appropriate values. }

Now in every piece of code that is overriding something in the core or is supposed to output something, I use this helper method.
Let's say you are overriding a method called getSomething() in a class. This is how your method should look like:

function getSomething($params){
    if (!Mage::helper('module_name')->getIsEnabled()){ //if my module is not enabled
        return parent::getSomething($params);
    }
    //your logic here.
}

Every .phtml in your module should look like this:

<?php if (Mage::helper('module_name')->getIsEnabled()) : //if my module is enabled?>
    <div>Block output here</div>
<?php endif; ?>

If all your template and overwritten methods look like this, you should be able to disable (simulate disable) from the configuration panel.

The admin section with all the modules does not disable the module. From there you can oly disable the output of some module. This means that the code is still executed but not output is generated.
Indeed, the way to disable a module is to change the tag <active> to false in the module declaration xml (app/etc/modules/Namespace_Module.xml) and clear the cache.
I don't think you can disable a module from code since the modules are loaded very early in the application (Mage_Core_Model_Config::_loadDeclaredModules()).
When building custom modules I also like to be able to disable them with 'one click'. Here is how I usually do it:

  • add in the system.xml an 'enabled' field.

    Module is enabled select adminhtml/system_config_source_yesno 1 1 1 1
  • create a method in the helper to check this flag

    public function getIsEnabled(){ return Mage::getStoreConfigFlag('section/group/enabled'); //replace section & group with appropriate values. }

Now in every piece of code that is overriding something in the core or is supposed to output something, I use this helper method.
Let's say you are overriding a method called getSomething() in a class. This is how your method should look like:

function getSomething($params){
    if (!Mage::helper('module_name')->getIsEnabled()){ //if my module is not enabled
        return parent::getSomething($params);
    }
    //your logic here.
}

Every .phtml in your module should look like this:

<?php if (Mage::helper('module_name')->getIsEnabled()) : //if my module is enabled?>
    <div>Block output here</div>
<?php endif; ?>

If all your template and overwritten methods look like this, you should be able to disable (simulate disable) from the configuration panel.

From the admin section with all the modules you cannot disable a module. From there you can only disable the output of some module. This means that the code is still executed but no output is generated.
Indeed, the way to disable a module is to change the tag <active> to false in the module declaration xml (app/etc/modules/Namespace_Module.xml) and clear the cache.
I don't think you can disable a module from code since the modules are loaded very early in the application (Mage_Core_Model_Config::_loadDeclaredModules()).
When building custom modules I also like to be able to disable them with 'one click'. Here is how I usually do it:

  • add in the system.xml an 'enabled' field.

    Module is enabled select adminhtml/system_config_source_yesno 1 1 1 1
  • create a method in the helper to check this flag

    public function getIsEnabled(){ return Mage::getStoreConfigFlag('section/group/enabled'); //replace section & group with appropriate values. }

Now in every piece of code that is overriding something in the core or is supposed to output something, I use this helper method.
Let's say you are overriding a method called getSomething() in a class. This is how your method should look like:

function getSomething($params){
    if (!Mage::helper('module_name')->getIsEnabled()){ //if my module is not enabled
        return parent::getSomething($params);
    }
    //your logic here.
}

Every .phtml in your module should look like this:

<?php if (Mage::helper('module_name')->getIsEnabled()) : //if my module is enabled?>
    <div>Block output here</div>
<?php endif; ?>

If all your template and overwritten methods look like this, you should be able to disable (simulate disable) from the configuration panel.

Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

The admin section with all the modules does not disable the module. From there you can oly disable the output of some module. This means that the code is still executed but not output is generated.
Indeed, the way to disable a module is to change the tag <active> to false in the module declaration xml (app/etc/modules/Namespace_Module.xml) and clear the cache.
I don't think you can disable a module from code since the modules are loaded very early in the application (Mage_Core_Model_Config::_loadDeclaredModules()).
When building custom modules I also like to be able to disable them with 'one click'. Here is how I usually do it:

  • add in the system.xml an 'enabled' field.

    Module is enabled select adminhtml/system_config_source_yesno 1 1 1 1
  • create a method in the helper to check this flag

    public function getIsEnabled(){ return Mage::getStoreConfigFlag('section/group/enabled'); //replace section & group with appropriate values. }

Now in every piece of code that is overriding something in the core or is supposed to output something, I use this helper method.
Let's say you are overriding a method called getSomething() in a class. This is how your method should look like:

function getSomething($params){
    if (!Mage::helper('module_name')->getIsEnabled()){ //if my module is not enabled
        return parent::getSomething($params);
    }
    //your logic here.
}

Every .phtml in your module should look like this:

<?php if (Mage::helper('module_name')->getIsEnabled()) : //if my module is enabled?>
    <div>Block output here</div>
<?php endif; ?>

If all your template and overwritten methods look like this, you should be able to disable (simulate disable) from the configuration panel.