Magento custom tab of category edit page
Magento custom tab of category edit page

Here I will give you the idea how to create custom tab in category edit page in admin section of magento. In this part I will just show you Magento custom tab of category edit page not the full description like how to save data into database.For doing custom tab with custom attribute you refer to next tutorial where I have explained well one by one with examples.So lets focus only this tutorial how we can simply create custom tab with our custom content on the selected tab.Sometime if we don’t like to use category attribute and we want to use some other extra features then we can do it easily or if you like to use category attribute then its simple you can use this tutorial.I am not explaining everything at first because if I will explain everything it may be weird for you .So lets us focus only on how to create Magento custom tab of category edit page.For this we can do it in two ways first either oy overriding adminhtml blocks Mage_Adminhtml_Block_Catalog_Category_Tabs or catching event by observer.So I always prefer to observer section which more reliable and portable. Lets lets start one bye one.

First Method:

By event observer:

Here for this section we need to have two files one registering file for registering the observer with our method in magento and then through Observer.php file we can do our custom code to add custom tab.Here I just defined the event adminhtml_catalog_category_tabs to catch the events and called my custom method to add custom tab on method of Observer.php file.

Config.xml:

Dir: app/code/[Code_Pool]/[NameSpace]/[ModuleName]/etc/config.xml
e.g: app/code/local/JRB/Customtab/etc/config.xml

< ?xml version="1.0"?>
<!--
/**
* category JRB
* package JRB_Customtab
* author Jyotiranjan Biswal <biswal@jyotiranjan.in>
*/
-->
<config>
    ..........................
    ..........................
    ..........................
    <global>
        <models>
            <customtab>
                <class>JRB_Customtab_Model</class>
                <resourcemodel>customtab_mysql4</resourcemodel>
            </customtab>
        </models>
        <events>
            <adminhtml_catalog_category_tabs><!-- identifier of the event we want to catch -->
                <observers>
                    <customtab_customtab_observer><!-- identifier of the event handler -->
                        <type>model</type><!-- class method call type; valid are model, object and singleton -->
                        <class>customtab/observer</class><!-- observers class alias -->
                        <method>addCategoryTab</method><!-- observer's method to be called -->
                        <args></args> <!-- additional arguments passed to observer -->
                    </customtab_customtab_observer>
                </observers>
            </adminhtml_catalog_category_tabs>
        </events>
    </global>
</config>
Observer.php:

Dir: app/code/[Code_Pool]/[NameSpace]/[ModuleName]/Model/Observer.php
e.g: app/code/local/JRB/Customtab/Model/Observer.php

< ?php
class JRB_Customtab_Model_Observer
{
    /**
     * add extra tab to block content 
     * category JRB
     * package JRB_Customtab
     * author Jyotiranjan Biswal <biswal@jyotiranjan.in>
     */
    public function addCategoryTab($observer)
    {
        $tabs = $observer->getEvent()->getTabs();
        $tabs->addTab('custom_tab', array(
            'label'     => Mage::helper('catalog')->__('Custom Tab'),
            'content'   => 'Here is the contents for my custom tab'
        ));
    }
}

Second Method:

By Overriding Adminhtml Block:

This is my second method through which you can add custom tab in magento category edit page.SO here I am going to override magento core block into my custom module.So lets see how will I override magento adminhtml block that is Mage_Adminhtml_Block_Catalog_Category_Tabs into custom module. Through this tutorial you may get little idea how to override magento block to custom module.For doing this I need to file fist the config.xml file and second my block file where I will extends the Mage_Adminhtml_Block_Catalog_Category_Tabs.So lets see .

config.xml:

Dir: app/code/[Code_Pool]/[NameSpace]/[ModuleName]/etc/config.xml
e.g: app/code/local/JRB/Customtab/etc/config.xml

<?xml version="1.0"?>
<!--
/**
* category JRB
* package JRB_Customtab
* author Jyotiranjan Biswal <biswal@jyotiranjan.in>
*/
-->
<config>
    ..............................
    ..............................
    ..............................
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_category_tabs>JRB_Customtab_Block_Catalog_Category_Tabs</catalog_category_tabs>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>
Tabs.php:

Dir: app/code/[Code_Pool]/[NameSpace]/[ModuleName]/Block/Catalog/Category/Tabs.php
e.g: app/code/local/JRB/Customtab/Block/Catalog/Category/Tabs.php

< ?php 
class JRB_Customtab_Block_Catalog_Category_Tabs extends Mage_Adminhtml_Block_Catalog_Category_Tabs
{
    /**
     * add extra tab to block content 
     * category JRB
     * package JRB_Customtab
     * author Jyotiranjan Biswal <biswal@jyotiranjan.in>
     */
    protected function _prepareLayout()
    {
        $this->addTab('custom_tab', array(
            'label'     => Mage::helper('catalog')->__('Custom Tab'),
            'content'   => 'Here is the contents for my custom tab'
        ));
        
	return parent::_prepareLayout();
    }
}

This tutorial was just simple explanation how to add custom tab in different method or procedures .For more features like creating attribute with group or for managing with custom form you can follow magento custom tab of category edit page with custom attribute

Hope you got your required solution and learned something from here And I guess you will share URL or bookmarked this URL for your other friends.

Magento custom tab of category edit page
Tagged on:                                         

2 thoughts on “Magento custom tab of category edit page

Leave a Reply

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