1

I have created a module, where admin can enable/disable and also select any value from select options.

Now I want this data to check that values, and according to that I want to give some conditions to display menu on header. (If admin enables this, the menu will be displayed in frontend).

How do i achieve this?

Please let me know any way to do this.

4

Put below code in your system file

    <?xml version="1.0"?>
    <config>
<tabs>
    <tab_name translate="label" module="Module_name">
        <label>Main tab name</label>
        <sort_order>500</sort_order>
    </tab_name>
</tabs>
<sections>
    <tab_name translate="label" module="Module_name">
        <label>Sub tab name</label>
        <tab>tab_name</tab>
        <frontend_type>text</frontend_type>
        <sort_order>110</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <general translate="label">
                <label>General</label>
                <frontend_type>text</frontend_type>
                <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>
                <fields>
                    <enabled translate="label">
                        <label>Enabled:</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>
                    </enabled>
                </fields>
            </general>
        </groups>
    </tab_name>
</sections>

After that check Enable/Disable in your phtml file

    <?php 
$config = Mage::getStoreConfig('tab_name/general/enabled');
if($config){
echo "Enable from admin";
}else{
echo "Disable from admin";
}
8
  • It only displays else condition even i enabled it from admin panel..? – onlyfordigitalworld Jun 2 '17 at 10:14
  • Print config value and check what value is in $config. After save both enable and disable from admin – ARVIND KARKAR Jun 2 '17 at 10:35
  • Also, I have mention select option data,so now i want to get that perticular option data,how could i achieve this? – onlyfordigitalworld Jun 2 '17 at 10:40
  • 1
    You can get dropdown value using same as enable/disable. Mage::getStoreConfig('tab_name/general/dropdown'); – ARVIND KARKAR Jun 2 '17 at 10:46
  • 1
    Please give upvote also. – ARVIND KARKAR Jun 2 '17 at 10:51
1

PHP/phtml files

You can use this to check your enabled/disabled settings:

Mage::getStoreConfigFlag('path/to/enable_disable') // returns true or false

For all other config values you can use:

Mage::getStoreConfig('path/to/configfield') // returns config value

Layout files

In layout.xml files you can check boolean config values like this:

<reference name="head">
    <action method="append" ifconfig="path/to/enable_disable">
        <block>my_block</block>
    </action>
</reference>

If you want to use show something based on you config string values, you may need an helper method:

<reference name="head">
    <action method="append">
        <block_id helper="yourmodule/yourhelper/checkConfig"/>
    </action>
</reference>

Your_Module_Helper_Data.php

public function checkConfig()
{
    $config = Mage::getStoreConfig('path/to/configfield');
    // your logic here
}
0

First of all call the value of enable disable fields from system.xml

$show = Mage::getStoreConfig('tab/general/enable_disable');

Then put your menu in if condition to display the header menu as below:

if($show == 1){
   echo 'Show Menu';
}else{
   echo 'Hide Menu';
}

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.