Search code examples
magento-1.9

How can I make my enable or disable dropdown box work for my custom extension?


I have made a query extension where you can ask your query, and then get a reply from admin. And I have already managed to get the extension setting tab added as a tab in the admin configuration area, and created "Product Query" menu also. successfully created this tab

Here are all of my files :) app/code/local/Vlabs/Productquery/etc/config.xml

 <?xml version="1.0"?>
<config>
    <modules>
        <Vlabs_Productquery>
            <version>0.1.0</version>
        </Vlabs_Productquery>
    </modules>

    <frontend>
        <routers>
            <productquery>
                <use>standard</use>
                <args>
                    <module>Vlabs_Productquery</module>
                    <frontName>productquery</frontName>
                </args>
            </productquery>
        </routers>
        <layout>
            <updates>
                <productquery module="Vlabs_Productquery">
                    <file>productquery.xml</file>
                </productquery>
            </updates>
        </layout>
    </frontend>

    <global>
        <blocks>
            <productquery>
                <class>Vlabs_Productquery_Block</class>
            </productquery>
        </blocks>

        <models>
            <productquery>
                <class>Vlabs_Productquery_Model</class>
                <resourceModel>productquery_Resource</resourceModel>
            </productquery>
            <productquery_Resource>
                <class>Vlabs_Productquery_Model_Resource</class>
                <entities>
                    <querybox>
                        <table>Vlabs_queryBox</table>
                    </querybox>
                </entities>
            </productquery_Resource>
        </models>
         <helpers>
          <productquery>
            <class>Vlabs_Productquery_Helper</class>
          </productquery>
        </helpers>
        <resources>
            <form_setup>
                <setup>
                    <module>Vlabs_Productquery</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </form_setup>
            <form_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </form_write>
            <form_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </form_read>
        </resources>
        <template>
        <email>
            <vlabs_query_email_template translate="label">
                <label>Recurring order email</label>
                <file>vlabs_querybox_email.html</file>
                <type>html</type>
            </vlabs_query_email_template>
        </email>
    </template>   
    </global>

    <admin>
        <routers>
            <adminhtml>
                <use>admin</use>
                <args>
                    <modules>
                        <Vlabs_Productquery before="Mage_Adminhtml">Vlabs_Productquery_Adminhtml</Vlabs_Productquery>
                    </modules>
                    <frontname>productquery</frontname>
                </args>
            </adminhtml>
        </routers>
    </admin> 
    <adminhtml>
        <layout>
            <updates>
                <productquery>
                    <file>productquery.xml</file>
                </productquery>
            </updates>
        </layout>
    </adminhtml>   
</config> 

app/code/local/Vlabs/Productquery/etc/adminhtml.xml

<config>
    <menu>
        <productquery>
            <title>Product Query</title>
            <sort_order>50</sort_order>

            <children>
                <query>
                    <title>Query</title>
                    <sort_order>1</sort_order>
                    <action>adminhtml/index/</action>
                </query>
                <settings>
                    <title>Settings</title>
                    <sort_order>2</sort_order>
                    <action>adminhtml/index/settings</action>
                </settings>
            </children>
        </productquery>     
    </menu>

    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <productquery>
                                        <title>Beckin Drop Down Shipping Extension</title>
                                    </productquery>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

app/code/local/Vlabs/Productquery/etc/system.xml

<?xml version="1.0"?>
<config>
<tabs>
<productquery translate="label">
    <label>Vyrazu Query Extension</label>
    <sort_order>100</sort_order>
</productquery>
</tabs>

<sections>  
    <productquery translate="label" module="productquery">
    <label>Query</label>
    <tab>productquery</tab>
    <frontend_type>text</frontend_type>
    <sort_order>1000</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
        <groups> 
            <settings translate="label" module="productquery">
                <label>Settings</label>
                <frontend_type>text</frontend_type>
                <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>       
            <fields>
                <enable translate="label">
                <label>Enable</label>
                <comment>
                <![CDATA[Enable or Disable this extension.]]>
                </comment>
                <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>                    
                </enable>           
            </fields>

            </settings>
        </groups>
    </productquery>
</sections>     
</config>

Please guide me, where I should write those code,by this i can disable or enable this extension with this disable/enable dropdown.


Solution

  • I solved the issue.May be someone will be helpfull by this answer. That's why I update my answer. So,at first write this anywhere to check it is working or not

    $enableorDisable = Mage::getStoreConfig('productquery/settings/enable',Mage::app()->getStore());
        print_r($enableorDisable); die();
    

    if answer is 0 when your module is disable and answer is 1, when your module is enable. then it is working fine.. And you have to add following line in your block.

    <action method="setTitle" translate="value" ifconfig="productquery/settings/enable"><value>Product Query</value></action>
    

    add ifconfig="modulename/group name/field name"

    Thank You..