Creating Additional Product Tabs in Magento Admin

When creating the Configurable Products Utility Magento extension, I had to figure out how to create an additional tab in the product admin. I found a few examples on the web, but none of them seemed to function exactly as I needed. It the end, it was not that difficult.

Magento Admin Tab Block

I first have to create a tab block. This block will be the container for 2 child blocks – one for the products, and the other for the product images.

/app/code/community/Grasshopperpebbles/Configurableproducts/Block/Adminhtml/Catalog/Product/Edit/Tab.php

class Grasshopperpebbles_Configurableproducts_Block_Adminhtml_Catalog_Product_Edit_Tab
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface {
 
    /**
     * Set the template for the block
     *
     */
    public function _construct()
    {
        parent::_construct();
 
        $this->setTemplate('configurableproducts/catalog/product/edit/tab/bulk_create.phtml');
    }
 
    /**
     * Retrieve the label used for the tab relating to this block
     *
     * @return string
     */
    public function getTabLabel()
    {
        return $this->__('Associated Products Bulk');
    }
 
 
    protected function _prepareLayout()
    {
        $this->setChild('bulkcreate',
            $this->getLayout()->createBlock('configurableproducts/adminhtml_catalog_product_edit_tab_bulkcreate')
        );
 
	$this->setChild('bulkimagecreate',
            $this->getLayout()->createBlock('configurableproducts/adminhtml_catalog_productimage_edit_tab_bulkimagecreate')
        );
 
        return parent::_prepareLayout();	
    }
}

In the constructor of the class, I set the template for the product tab. The label for the tab is displayed using the getTabLabel method.

product_tab

In the _prepareLayout method, I create two child blocks: bulkcreate and bulkcreateimage.

Magento Block Template

Next I have to add the child blocks to the tab block template.

/app/design/adminhtml/default/default/template/configurableproducts/catalog/product/edit/tab/bulk_create.html

<?php echo $this->getChildHtml('bulkcreate'); ?>
<?php echo $this->getChildHtml('bulkimagecreate'); ?>

Tab Attributes

The two child blocks extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes. Each are created as fieldsets. The example below displays the first fieldset.

/app/code/community/Grasshopperpebbles/Configurableproducts/Block/Adminhtml/Catalog/Product/Edit/Tab/Bulkcreate.php

class Grasshopperpebbles_Configurableproducts_Block_Adminhtml_Catalog_Product_Edit_Tab_Bulkcreate 
	extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes
{
    protected function _prepareForm()
    {
        ...
	$form = new Varien_Data_Form(array('id' => 'bulk-create-form', 'enctype' => 'multipart/form-data'));
 
        $form->setFieldNameSuffix('bulk_create');
        $form->setDataObject($this->_getProduct());
 
 	$fieldset = $form->addFieldset('configurableproducts_bulkcreate', array(
            'legend' => Mage::helper('configurableproducts')->__('Bulk Create Simple Products')
        ));
 	$this->_addElementTypes($fieldset);
	...
    }
}

That’s it. Creating additional Product tabs in the Magento admin can be confusing at times, but is simple once you understand the structure. Enjoy.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks