Adding a new tab to the product edit page in admin

Adding a new tab to the product edit page in admin

There are 2 ways to add a new tab to the product edit page in admin panel of Magento.

First method:
Let’s add a tab for a custom module.
Add the following code to your config.xml file in the global scope:

<blocks>
...
    <modulename>
        <class>Company_ModuleName_Block</class>
    </modulename>
    <adminhtml>
        <rewrite>
             <catalog_product_edit_tabs>Company_ModuleName_Block_Adminhtml_Tabs</catalog_product_edit_tabs>
         </rewrite>
     </adminhtml>
...
</blocks>

After this you should create a new file: Company/ModuleName/Block/Adminhtml/Tabs.php The content of this file you can see below

<?php

class Company_ModuleName_Block_Adminhtml_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
{
    private $parent;

    protected function _prepareLayout()
    {
        //get all existing tabs
        $this->parent = parent::_prepareLayout();
        //add new tab
        $this->addTab('tabid', array(
                     'label'     => Mage::helper('catalog')->__('New Tab'),
                     'content'   => $this->getLayout()
             ->createBlock('modulename/adminhtml_tabs_tabid')->toHtml(),
        ));
        return $this->parent;
    }
}

The code above rewrites the system function which generates the layout and adds the tab.

Next, you need to create a file: Company/ModuleName/Block/Adminhtml/Tabs/Tabid.php

<?php

class Company_ModuleName_Block_Adminhtml_Tabs_Tabid extends Mage_Adminhtml_Block_Widget
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('modulename/newtab.phtml');
    }
}

Note: template should be in app/design/adminhtml/…/…/template/

Second method:

Simply copy the file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php to a local folder (app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php) and add the following snippet to the function _prepareLayout()

$this->addTab('tabid', array(
              'label'     => Mage::helper('catalog')->__('New Tab'),
              'content'   => $this->_translateHtml($this->getLayout()
     ->createBlock('modulname/adminhtml_tabs_tabid')->toHtml()),
));

After this, simply follow the instructions above.

We hope this article was helpful. Comments are welcome.

Clients

Smart Brands Choose Us.

From Mark Cuban and Sir Richard Branson backed startups, to Inc 500 US Fastest Growing Companies and Global Brands choose us to deliver and support unparalleled eСommerce experience for their customers.