If you are trying to add a custom tab to the product add/edit page in Magento admin, then you are at the right place. Today I will tell you a damn simple method to add the custom tab to product add/edit page. We will have to add few lines to the xml layout file of your custom module. Then create a phtml file that contains the html part to be shown in the tab.
Here is the detailed description of the process:
1. Create a directory named 'custom' at app\design\adminhtml\default\default\template location.
2. Create file named content.phtml in the above directory so that the full path looks like app\design\adminhtml\default\default\template\custom\content.phtml
3. In content.phtml you can write any php and html code according to your need.
4. Create the block file in app\code\local\<namespace>\<module_name>\Block\Adminhtml\Config.php. Add following content to the file:
5. Open the app\design\adminhtml\default\default\layout\<module_name>.xml. Add following lines to this file:
This is all and you are done! Please share if you like it.
Here is the detailed description of the process:
1. Create a directory named 'custom' at app\design\adminhtml\default\default\template location.
2. Create file named content.phtml in the above directory so that the full path looks like app\design\adminhtml\default\default\template\custom\content.phtml
3. In content.phtml you can write any php and html code according to your need.
<?php
//Get the current product
$product = Mage::registry('product');
?>
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">Custom Tab</h4>
</div>
<div id="group_fields4" class="fieldset fieldset-wide">
<?php
var_dump($product);
?>
</div>
</div>
4. Create the block file in app\code\local\<namespace>\<module_name>\Block\Adminhtml\Config.php. Add following content to the file:
<?php
class <namespace>_<module_name>_Block_Adminhtml_Config extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function __construct(){
$this->setTemplate('custom/content.phtml');
parent::__construct();
}
//Label to be shown in the tab
public function getTabLabel(){
return Mage::helper('core')->__('Custom Tab');
}
public function getTabTitle(){
return Mage::helper('core')->__('Custom Tab');
}
public function canShowTab(){
return true;
}
public function isHidden(){
return false;
}
}
5. Open the app\design\adminhtml\default\default\layout\<module_name>.xml. Add following lines to this file:
<!-- To add a tab on new product page -->
<adminhtml_catalog_product_new>
<reference name="product_tabs">
<action method="addTab">
<name>custom_tab</name>
<block template="custom/content.phtml">module_name/adminhtml_config</block>
</action>
</reference>
</adminhtml_catalog_product_new>
<!-- To add a tab on new product page -->
<!-- To add a tab on edit product page -->
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<name>custom_tab</name>
<block template="custom/content.phtml">module_name/adminhtml_config</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
<!-- To add a tab on edit product page -->
Hi Arvind!
ReplyDeleteThanks for this great post, but I see one problem. The new tab is also visible in the "new product"-page, where you can define a simple, configured product et cetera. How can I prevent the tab is displayed?
Regards,
Danilo