Thursday, September 27, 2012

Magento : Add configuration setting for custom module

Consider module Bd_Demo and model Test, then
Create System.xml in your module demo/etc
<?xml version="1.0"?>
<config>
    <tabs>
        <demo module="demo" translate="label">
            <label>Tab name</label>
            <sort_order>100</sort_order>
        </demo>
    </tabs>
  <sections>
    <demosection module="demo" translate="label">
      <label>Settings</label>
      <tab>demo</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>
        <demogroup translate="label">
          <label>External Datatbase</label>
          <frontend_type>text</frontend_type>
          <sort_order>100</sort_order>
          <show_in_default>1</show_in_default>
          <show_in_website>1</show_in_website>
          <show_in_store>1</show_in_store>
          <fields>
            <!-- New fields go here -->
         <demofield translate="label comment">
              <label>Test Name</label>
              <comment>
                <![CDATA[This text appears just beneath the field with a small arrow.
                <span class="notice">It can contain HTML formatting too!</span>]]>
              </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>
            </demofield>    

          </fields>
        </demogroup>
      </groups>
    </demosection>
  </sections>
</config>

Then Define ACL in config.xml
<config>
    <adminhtml>
        <acl>
            <resources>
                <all>
                <title>Allow Everything</title>
                </all>
            <admin>
                <children>
                    <system>
                            <children>
                                <config>
                                    <children>
                                        <demosection>
                                            <title>Demo name</title>
                                                <children>
                                                    <demogroup>
                                                        <title>Settings</title>
                                                        <sort_order>1</sort_order>
                                                    </demogroup>
                                                   
                                                </children>
                                        </<demosection>
                                    </children>
                                </config>
                            </children>
                                </system>
                </children>
            </admin>
            </resources>
        </acl>
    </adminhtml>
</config> 

Also we access the value of this filed  as
Mage::getStoreConfig('demosection/demogroup/demofield ');

Also we can define the default value of this filed in config.xml
<config>
<default>
        <demosection>
            <demogroup>
                  <model>demo/test</model>                 
                  <demofield>Default Value</demofield>
            </demogroup>
        </demosection>
</default>
</config>

1 comment:

  1. Really awesome blog. Your blog is really useful for me.
    Thanks for sharing this informative blog. Keep update your blog.
    Outsource magento development company india
    Outsource magento ecommerce development services

    ReplyDelete