Magento: Add Custom Module For Custom Admin Config Options

Magento has a very powerful admin configuration system. It allows you to create config forms to be able to configure your custom modules from admin panel, also to enable users to modify it.

t’s quite simple to do – and it should only take you a few minutes to implement this. But, the options are endless. You can add all sorts of custom configurable options that you can edit in the admin panel very easily.

Here my simplified module:

local/SWT/Mymodule/etc/config.xml

<?xml version=”1.0″?>
<config>
<modules>
<SWT_Mymodule>
<version>0.1.0</version>
</SWT_Mymodule>
</modules>
<global>
<models>
<mymodule>
<class>SWT_Mymodule_Model</class>
</mymodule>
</models>
<helpers>
<mymodule>
<class>SWT_Mymodule_Helper</class>
</mymodule>
</helpers>
<resources>
<mymodule_setup>
<setup>
<module>SWT_Mymodule</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mymodule_setup>
</resources>
</global>

<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<mymodule>
<title>My Module Section</title>
</mymodule>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
<translate>
<modules>
<SWT_Mymodule>
<files>
<default>SWT.csv</default>
</files>
</SWT_Mymodule>
</modules>
</translate>
</adminhtml>

<default>
<mymodule>
<mymoduleconfig>
<host><![CDATA[localhost]]></host>
<active>1</active>
</mymoduleconfig>
</mymodule>
</default>
</config>

local/SWT/Mymodule/etc/system.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<tabs>
<mymodule translate=”label” module=”mymodule”>
<label>SWT</label>
<sort_order>200</sort_order>
</mymodule>
</tabs>
<sections>
<mymodule translate=”label” module=”mymodule”>
<label>My Module</label>
<tab>mymodule</tab>
<frontend_type>text</frontend_type>
<sort_order>102</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<schedep translate=”label”>
<label>My Module 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>

<active translate=”label”>
<label>Enabled</label>
<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>0</show_in_store>
</active>
</fields>
</schedep>
</groups>
</mymodule>
</sections>
</config>

local/SWT/Mymodule/Helper/Data.php

<?php

class SWT_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract {

}

?>

local/SWT/Mymodule/Model/Mymodule.php

<?php

class SWT_Mymodule_Model_Mymodule extends Mage_Core_Model_Abstract
{

protected function _construct()
{
$this->_init(‘mymodule/mymodule’);
}

protected function _beforeSave()
{
return parent::_beforeSave();
}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *