1

After a week of full hard work and coding i have successfully developed a magento extension which is working as expected but when i disable the module from magento admin config it still overriding the functionality, i have read about setting false in module global config files but don't getting how can i do this programatically.

Any one have any idea how this can be solve ?

Thanks

6

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.

<enabled translate="label" module="news">
    <label>Module is enabled</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_yesno</source_model>
    <sort_order>1</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</enabled> 

- 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.

  • Thanks man for detailed explanation , but get disappointed i can't disable it permanently the code still executes.. :-( – ravisoni Jun 9 '13 at 18:25
  • @Marius, if my module has a URL that shows custom listing, then even if I disable the module, it will still show the listing and 404 page not found. – Slimshadddyyy Jul 24 '14 at 11:58
  • @Vikram. I don't understand. add a question related to this and explain what is the problem. Screenshots can help also. – Marius Jul 24 '14 at 12:08
8

Marius is quite right except one thing.

Even disabling module by setting active to false in the bootstrap file is not enough in case some other module is extending it's class or using it's template.

So to be 100% sure the extension is disabled you also have to remove it's all files or at least rename directories/files.

  • 1
    Right. Thanks Tim. Even if the chance is small of this happening it still exists. That's why you should declare the dependencies int the bootstrap file. That way if you disable a module by setting active to false and an other module depends on the one you just deactivated, you should get an error and realize what's wrong. – Marius Jun 9 '13 at 19:11
  • @Marius : absolutely right. – Rajeev K Tomy Sep 24 '14 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.