PHP Magento Tips

Add admin menu and System Configuration Option in Magento

Rate this posting:
{[['']]}

Here is a sample code showing how to easily add your own menu in Magento Admin and your own configuration settings in Magento.

Step 1:

In  app/etc/modules/Training_Animal.xml add below code:

<?xml version="1.0"?>

<config>

    <modules>

        <Training_Animal>

            <active>true</active>

            <codePool>local</codePool>

            <depends>

                <Mage_Core />

             </depends>

        </Training_Animal>

    </modules>

</config>

Step 2:

In app/code/local/Training/Animal/etc/config.xml add below code:

<?xml version="1.0"?>

<config>

    <modules>

        <Training_Animal>

            <version>1.0.0</version>

        </Training_Animal>

    </modules>

    <global>

        <helpers>

            <training_animal>

                <class>Training_Animal_Helper</class>

            </training_animal>

        </helpers>

        <models>

            <training_animal>

                <class>Training_Animal_Model</class>

            </training_animal>

        </models>

    </global>

    <adminhtml>

        <layout>

            <updates>

                <training_animal>

                    <file>training_animal.xml</file>

                </training_animal>

            </updates>

        </layout>

    </adminhtml>

    <admin>

        <routers>

            <adminhtml>

                <args>

                    <modules>

                        <Training_Animal before="Mage_Adminhtml">Training_Animal_Adminhtml</Training_Animal>

                    </modules>

                </args>

            </adminhtml>

        </routers>

    </admin>

</config>


Step 3:

In app/code/local/Training/Animal/etc/adminhtml.xml add below code:

<?xml version="1.0"?>
<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <training_animal translate="title" module="training_animal">
                                        <title>Animal</title>
                                    </training_animal>
                                </children>
                            </config>
                        </children>
                    </system>
                    <training_animal translate="title" module="training_animal">
                        <title>Manage Animals</title>
                        <children>
                            <stall translate="title" module="training_animal">
                                <title>Stall</title>
                                <sort_order>0</sort_order>
                            </stall>
                        </children>
                    </training_animal>
                </children>
            </admin>
        </resources>
    </acl>
    <menu>
     <catalog>
        <children>
          <training_animal translate="title" module="training_animal">
              <title>Manage Animals</title>
              <sort_order>25</sort_order>
              <children>
                  <stall translate="title" module="training_animal">
                      <title>Stall</title>
                      <action>adminhtml/animal/index</action>
                      <sort_order>0</sort_order>
                  </stall>
              </children>
          </training_animal>
      </children>
  </catalog>
    </menu>
</config>


Note: If you are adding the top level menu item, then the path for <acl> <resources> <admin> <children> and then your node which should match up with the node should have the same value or the node name should be the same as what is configured under menu. That's what the connection happens.

Step 4:

In app/code/local/Training/Animal/etc/system.xml add below code:

<?xml version="1.0"?>
<config>
    <tabs>
        <training translate="label" module="training_animal">
            <label>Training</label>
            <sort_order>2000</sort_order>
        </training>
    </tabs>
    <sections>
        <training_animal translate="label" module="training_animal">
            <class>separator-top</class>
            <label>Animal</label>
            <tab>training</tab><!-- check node after tabs -->
            <sort_order>130</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">
                    <label>General Animal Settings</label>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>0</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <recommendation translate="label">
                            <label>Recommendation</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <depends>
                    <show_recommendation>1</show_recommendation>
                  </depends>
                  <comment><![CDATA[<strong>This</strong> is a comment]]></comment>
                  </recommendation>
                  <show_recommendation translate="label">
                 <label>Display recommendation</label>
                 <frontend_type>select</frontend_type>
                 <!-- Check node just after models in config.xml -->
                 <source_model>training_animal/system_config_source_show</source_model>
                 <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>
                 <tooltip>Wow! More JS PLS!</tooltip>
               </show_recommendation>
                    </fields>   
                </general>
                </groups>
            </training_animal>
    </sections>
</config>

Step 5:

In app/code/local/Training/Animal/controllers/Adminhtml/AnimalController.php add below code:

<?php
class Training_Animal_Adminhtml_AnimalController extends Mage_Adminhtml_Controller_Action
{
  public function indexAction() {
   $this->loadLayout();
   $this->_title(Mage::helper('training_animal')->__('Manage Animals'))
   ->_title(Mage::helper('training_animal')->__('Stalls'));
   $this->renderLayout();
  }
  
  protected function _isAllowed()
  {
   return Mage::getSingleton('admin/session')->isAllowed('training_animal/stall');
  }
}

Step 6:

In app/code/local/Training/Animal/Helper/Data.php add below code:

<?php



class Training_Animal_Helper_Data extends Mage_Core_Helper_Abstract

{

   

}

Step 7:

In app/code/local/Training/Animal/Model/System/Config/Source/Show.php add below code:

<?php

class Training_Animal_Model_System_Config_Source_Show {

 public function toOptionArray() {
  return array(
   array('value' => 0, 'label'=>Mage::helper('training_animal')->__('Hide')),
   array('value' => 1, 'label'=>Mage::helper('training_animal')->__('Show')),
  );
 }
}

Step 8:

In app/design/adminhtml/default/default/layout/training_animal.xml add below code:

<?xml version="1.0"?>

<layout>

</layout>


Now in Admin under "Catalog" menu you will find your new menu. And also in system configuration you will see your settings there.

Also add new value in your "core_config_data" table with path as "training_animal/general/recommendation" (section/groups/fields) and value as "Eat them All!" to get predefined values in system configuration.

Download Whole Module From Github: https://github.com/vijayrami/Training_Animal_Menu_System
Tag : Magento
0 Comments On "Add admin menu and System Configuration Option in Magento"

Back To Top