Question

I am working on creating my very first community extension. It is a very simple one and is already working. I would like to learn how to add my extension to the admin area that will allow the customer to disable or enable it. What do I need to add to my module to be able to do this? Any help would be great!

Here is my code:

app/etc/modules/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Module_Name>

        <!-- Whether our module is active: true or false -->
        <active>true</active>

        <!-- Which code pool to use: core, community or local -->
        <codePool>community</codePool>

    </Module_Name>
</modules>
</config>

etc/system.xml

<?xml version="1.0"?>
<config>
<sections>
    <module translate="label" module="modulename">
        <label>Your Module Name</label>
        <tab>tab_id_where_you_want_to_add_your_section</tab>
        <frontend_type>text</frontend_type>
        <sort_order>980</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>0</show_in_store>
        <groups>
            <modulename>
                <label>Your Group Title</label>
                <sort_order>10</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>0</show_in_store>
                <fields>
                    <comment translate="label comment">    
                        <label>Your Field Title</label>
                        <comment>Your Comment</comment>    
                        <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>0</show_in_store>
                    </comment>
                </fields>
            </modulename>
        </groups>
    </your_module>
</sections>
</config>

etc/adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<menu>
    <modulename translate="title" module="shipping">
        <title>Module</title>
        <sort_order>15</sort_order>
        <children>
            <modulename translate="title" module="modulename">
                <title>Drop Down Shipping</title>
                <sort_order>1</sort_order>
                <action>adminhtml/shipping/index</action>
            </example>
        </children>
    </modulename>
</menu>

    <layout>
        <updates>
            <modulename>
                <file>shipping.xml</file>
            </modulename>
        </updates>
    </layout>
  <acl>
    <resources>
        <admin>
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <modulename translate="title" module="shipping">
                                    <title>Your Module Name</title>
                                </modulename>
                            </children>
                        </config>
                    </children>
                </system>
            </children>
        </admin>
    </resources>
  </acl>

</config>

etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config> 
<modules>
    <Module_Name>

        <version>0.0.1</version>

    </Module_Name>

</modules>

<frontend>
    <layout>
        <updates>
            <modulename>
                <file>shipping.xml</file>
            </modulename>
        </updates>
    </layout>
</frontend>

<global>
    <helpers>
        <modulename>
            <class>Module_Name_Helper</class>
        </modulename>
    </helpers>
</global>

</config>

My theme Layout XML File:

<?xml version="1.0"?>

<layout version="0.1.0">

<checkout_cart_index>
<reference name="head">
    <action method="addCss"><stylesheet>css/module/shipping.css</stylesheet></action> 
</reference>
<reference name="checkout.cart.shipping">
 <action method="setTemplate"><template>module/shipping.phtml</template></action>
</reference>
</checkout_cart_index> 

</layout>

Helper/Data.php

<?php

class Module_Name_Data extends Mage_Core_Helper_Abstract
{

}
Was it helpful?

Solution

It is not quite clear from your question if you want to add node to main admin menu (horizontal one with fly-out sub-menus) or sidebar menu of System\Configuration screen. Below are instructions how to add section, group and field to Magento configuration screen.

First you need the etc/system.xml file to your module:

<?xml version="1.0"?>
<config>
    <sections>
        <your_module translate="label" module="your_module_shortcode">
            <label>Your Module Name</label>
            <tab>tab_id_where_you_want_to_add_your_section</tab>
            <frontend_type>text</frontend_type>
            <sort_order>980</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
            <groups>
                <your_group_name>
                    <label>Your Group Title</label>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <your_field_name translate="label comment">    
                            <label>Your Field Title</label>
                            <comment>Your Comment</comment>    
                            <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>0</show_in_store>
                        </your_field_name>
                    </fields>
                </your_group_name>
            </groups>
        </your_module>
    </sections>
</config>

And then add the following section to your etc/adminhtml.xml. It adds your newly created section to ACL so you will be able to control admin roles that can access it:

<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <your_module translate="title" module="your_module_shortcode">
                                        <title>Your Module Name</title>
                                    </your_module>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

OTHER TIPS

The enable and disable module feature is already exist in System >> Configuration >> ADVANCE >> Advance.

BTW if you want to add Menu in the System >> Configuration page, this article may help you http://alanstorm.com/custom_magento_system_configuration.

And if you got an error, check again whether everything is ok or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top