0

I already know how to disable module output in the system config by going to System>Configuration>Advanced and by setting <active>false</active> in etc/modules. What I want to know is how to disable module using the custom tab that I created using system.xml.

markaugustine
  • 77
  • 1
  • 9

3 Answers3

1

Add this code to your system.xml

<fields>
    <enable translate="label">
        <label>Enable</label>
        <frontend_type>select</frontend_type>
        <source_model>adminhtml/system_config_source_yesno</source_model>
        <sort_order>0</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <comment>enable/disable the module</comment>
    </enable>
</fields>

And check this in your code: before your first Action in the module.(this might be in your cron.php or observer.php or indexcontroller)

$isenabled = Mage::getStoreConfig('section_name/group_name/enable');
if (!$isenabled) {
    return;
}
sv3n
  • 319
  • 4
  • 17
NID
  • 3,238
  • 1
  • 17
  • 28
  • I'd suggest `Mage::getStoreConfigFlag` since it returns `boolean` value. – sv3n Jul 26 '17 at 08:30
  • @sv3n Their only difference is that getStoreConfig() will return the exact value while getStoreConfigFlag(), as its name suggests, returns boolean true or false. Both methods send us to Mage_Core_Model_Store::getConfig() – NID Jul 26 '17 at 08:41
  • 1
    I know ... in my opinion `Mage::getStoreConfig` should be used for all fields where you want to get the exact value. For all others (yes/no or enabled/disabled) I'd use `Mage::getStoreConfigFlag` since `if (0)` is not completly equal to `if (false)`. Still correct answer :) – sv3n Jul 26 '17 at 08:49
  • @sv3n Yeah i totally agree with you – NID Jul 26 '17 at 08:50
  • 1
    I found the solution already. It's almost the same as this one, but what I actually did is I created fields in system.xml file and added ACL in adminhtml.xml, I made a method in Helper that checks if its enabled or not using getStoreConfigFlag, and lastly, I placed and if else condition in the block where I want it to get affected. Thank you so much for the ideas. :) – markaugustine Jul 27 '17 at 03:09
0

You can add that New Enable/Disable field in system.xml , and before your module any code execute check this field value if that is enable then execute otherwise not,this way it can be possible.

0

you have to use ifconfig in your xml file

for example you make a field in your system.xml

 <enable translate="label">
<label>enable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>

And in your xml file

<block class="your Blockname" name="name of field" ifconfig="sectionname/groupname/enable">

using if config if your module is enable then it will display otherwise it will not display..!

Sanjay Gohil
  • 306
  • 1
  • 14