Enable / Disable the Custom Module in magento

Enable / Disable the Module in magento:
Normally in magento, there is option is there to make enable or disable the module by xml configuration and admin configuration.
If xml base then we have to make true (or) false in our module xml file
Ex: XML config
root/app/etc/modules
<Jute_Mymodule>
              <active>true</active>
              <codePool>local</codePool>
</Jute_Mymodule>

Admin configuration:
Instead of open the etc file and change the code level setting, will use admin option.
Admin -> System -> Configuration -> Advanced -> Make Enable (or) Disable.

Once done the above changes we have to clear the cache and check. Your module will be goto disable mode. Then that module won’t run or show in frontend of the website. In some scenario after done the above changes, you need to check whether this module is enabled or not. For that call below code and check your module is enabled or not.

if(Mage::getConfig()->getModuleConfig(‘Jute_Mymodule’)->is(‘active’, ‘true’)){
         echo “Yes module is Active”;
}else{
        echo “Yes module is Deactive”;
}

Custom Option:
In some scenario will we have our custom option is there to make enable or disable the module with our system config code.
Ex:
Add below code in your module system config file. Module/etc/system.xml. Clear cache and check it. This enable/disable dropdown will show in admin section. Currently in below code am not mention any tab. Which mean where this setting (dropdown option) should show in admin. In your code you can mention in which place (under which menu) this option should show.

<?xml version=”1.0″?>
<config>
…..
<mymodule_mymodule_enabledisable translate=”label”>
<label>Mymodule Enable / Disable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_enabledisable</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>
</mymodule_mymodule_enabledisable>
….
</config>

Once above code is add. clear your cache. and add below code wherever you want. Based on the current store this will return whethere your module is enabled or not for the current store.

$enableorDisable = Mage::getStoreConfig(‘mymodule/mymodule_option/mymodule_enabledisable’,Mage::app()->getStore());

Leave a Reply