Add Custom Fields in Magento Admin Panel




 Source code

system.xml file content (inside etc/ folder of your extension):

<?xml version="1.0"?>
<config>
    <tabs>
        <myconf translate="label">
            <label>My Configuration</label>
            <sort_order>150</sort_order>
        </myconf>
    </tabs>
    <sections>
        <tab1 translate="label" module="adminhtml">
            <label>Tab #1</label>
            <tab>myconf</tab>
            <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>
            <groups>
                <general translate="label comment">
                    <label>General</label>
                    <sort_order>50</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <comment><![CDATA[This is a <strong>global comment</strong> about my <em>configuration</em>.<br />You can specify <u>custom html</u> tags. <a href="http://www.bubblecode.net/en" target="_blank">Click here for example!</a>]]></comment>
                    <fields>
                        <text_field translate="label comment">
                            <label>Text Field</label>
                            <comment>Text field with store view scope.</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>1</show_in_store>
                        </text_field>
                        <textarea translate="label comment">
                            <label>Textarea</label>
                            <comment>Textarea with store view scope.</comment>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </textarea>
                        <dropdown translate="label comment">
                            <label>Dropdown</label>
                            <comment>Dropdown with global scope.</comment>
                            <frontend_type>select</frontend_type>
                            <source_model>jr_customconfigexample/system_config_source_dropdown_values</source_model>
                            <sort_order>30</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </dropdown>
                        <multiple_dropdown translate="label comment">
                            <label>Multiselect</label>
                            <comment>Multiselect with global scope.</comment>
                            <frontend_type>multiselect</frontend_type>
                            <source_model>jr_customconfigexample/system_config_source_dropdown_values</source_model>
                            <sort_order>40</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </multiple_dropdown>
                        <file translate="label comment">
                            <label>File</label>
                            <comment><![CDATA[File saved in <strong><span style="color: red;">var/uploads</span></strong> folder.]]></comment>
                            <frontend_type>file</frontend_type>
                            <backend_model>adminhtml/system_config_backend_file</backend_model>
                            <upload_dir>var/uploads</upload_dir>
                            <sort_order>50</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </file>
                        <time translate="label comment">
                            <label>Time</label>
                            <frontend_type>time</frontend_type>
                            <sort_order>52</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </time>
                        <active translate="label comment">
                            <label>Enable/Disable</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>54</sort_order>
                            <source_model>adminhtml/system_config_source_enabledisable</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </active>
                        <heading_example translate="label">
                            <label>Heading example</label>
                            <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
                            <sort_order>55</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </heading_example>
                        <boolean translate="label comment">
                            <label>Boolean</label>
                            <comment>Boolean with website scope and dependant fields when Yes is selected.</comment>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>60</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </boolean>
                        <dependant_text_field translate="label comment">
                            <label>Dependant Text Field</label>
                            <comment>This field depends of boolean value above.</comment>
                            <frontend_type>text</frontend_type>
                            <sort_order>70</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <depends>
                                <boolean>1</boolean>
                            </depends>
                        </dependant_text_field>
                    </fields>
                </general>
            </groups>
        </tab1>
    </sections>
</config>



config.xml file content (inside etc/ folder of your extension):

<?xml version="1.0"?>
<config>
    <modules>
        <JR_CustomConfigExample>
            <version>0.1.0</version>
        </JR_CustomConfigExample>
    </modules>
    <global>
        <models>
            <jr_customconfigexample>
                <class>JR_CustomConfigExample_Model</class>
            </jr_customconfigexample>
        </models>
    </global>
    <default>
        <tab1>
            <general>
                <text_field>Default value</text_field>
                <textarea></textarea>
                <dropdown>key2</dropdown>
                <multiple_dropdown>key1,key2</multiple_dropdown>
                <time>11,30,45</time>
                <active>0</active>
                <boolean>1</boolean>
                <dependant_text_field>Default value</dependant_text_field>
            </general>
        </tab1>
    </default>
</config>



adminhtml.xml file content (inside etc/ folder of your extension):

<?xml version="1.0"?>
<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <tab1>
                                        <title>Tab #1</title> <!-- Used in resources tree -->
                                    </tab1>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

Comments

Popular Posts

Magmi Single and Multiple Category Importer