1

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
{

}

2 Answers2

0

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>
user487772
  • 8,800
  • 5
  • 47
  • 72
  • Thank you Tim for better explaining this to me. I have followed your steps and updated my coding above. My extension is now working again. However, I do not understand what the tab_id is suppose to be. I am wanting to add this custom menu to the left sidebar under configurations. The only thing I need it to do is have the option to enable or disable. Can you help me with what I am missing above? –  Dec 14 '12 at 06:45
  • If you take a look at sidebar menu you will notice that it is divided into so called tabs (e.g. General, Catalog, Customers, Sales etc). So for example if you want to add your section to let's say Sales tab use `sales` instead of `tab_id`. Of course you can add your own tab but in most cases you can put your extension under one of existing ones. – user487772 Dec 14 '12 at 07:11
  • @tech0925 http://alanstorm.com/custom_magento_system_configuration (self link, but an full recap is a bit much for an answer/comment) – Alana Storm Dec 14 '12 at 07:12
  • Thank you @Alan Storm !!! That link really helped. I am now reconfiguring my extension based on that layout. I will be posting hopefully my one last question once I get it working. It will be concerning how to change the code just to show an enable and disable feature. Thanks again!!! –  Dec 14 '12 at 17:02
  • Thanks so much for the help! I was able to get it working via that link Tim. I have posted a final question regarding enabling and disabling the extension if anyone would like to try to help me. Again, thank you! http://stackoverflow.com/questions/13884508/custom-magento-extension-how-can-i-add-the-option-to-enable-or-disable-it –  Dec 14 '12 at 18:44
0

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.

Wakanina
  • 592
  • 3
  • 6
  • 20
  • Thanks for the link!! I am well aware of the advance disabling and enabling of extensions. However, that is not what I want. Most customers are probably not even aware of that option. Plus I plan on building lots of extensions when I get the hang of this so I would like a custom tab with our company name.. Thanks again! –  Dec 14 '12 at 17:04