If you want to add a tab to a product edit page in Magento backend, you can do this by following these steps:
- Create a new tab block {module_name}/adminhtml_{block_name}
class Magestore_{module_name}_Block_Adminhtml__{block_name} extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface { public function __construct() { parent::__construct(); } public function getTabLabel(){ return Mage::helper('core')->__('My tab'); } public function getTabTitle(){ return Mage::helper('core')->__('My tab'); } public function canShowTab(){ return true; } public function isHidden(){ return false; } }
- Add to layout file of your module:
<adminhtml_catalog_product_edit> <reference name="product_tabs"> <action method="addTab"><name>my_tab</name><block>{module_name}/adminhtml_{block_name}</block></action> </reference> </adminhtml_catalog_product_edit>
- Result:
Note: You can use this way to add a tab to order view page or customer view page.
See you again in future Magento tutorials from Magento blog.
13 Comments
Thanks for help and publish this article.
I have done this sucessfully in local magento setup.
but i have not found the solution for how to save added fields in my tab view.
I have tried to extend product controller but it gives error.
Do you have a sample with this code?
Thx.
My problem is solved..
Thanks for tutorial.
Thank you for the tutorial, but I don’t understand what does it mean to Create a new tab block ? where? what type of file should I create?
@shani: This is to add a new tab in product edit page in backend.
@Alex: This is a good trick but if you just want to create a new tab for product, there is another simple way. Here’s short instruction:
1) Create a new attribute set
2) Create a new group for that attribute set
3) Add attribute to the new group
Now you will have a new tab in product edit page.
Maybe this way is useful in some cases 😉
Hello,
I’ve tried to add a new tab to the product edit page in the admin area. I’ve found this tutorial on how to add my own tab but I ran into some problems.
I have an admin module I’ve added to magento and worked fine which is located in this folder: \app\code\local\Shani\Suppliers\
following the tutorial I did this steps:
The file adminhtml_Suppliers.php on this path: \app\code\local\Shani\Suppliers. The file content:
__(‘My tab’);
}
public function getTabTitle(){
return Mage::helper(‘core’)->__(‘My tab’);
}
public function canShowTab(){
return true;
}
public function isHidden(){
return false;
}
}
The file suppliers.xml on this path : \app\design\adminhtml\default\default\layout –
my_tabsuppliers/adminhtml_suppliers
and in the file config.xml on this path : \app\code\local\Shani\Suppliers\etc\ –
Suppliers
71
…
Allow Everything
Suppliers Module
10
suppliers.xml
after I do those steps I get an error in the admin:
a:5:{i:0;s:274:”Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : attributes construct error in /home/…/public_html/…/app/code/core/Mage/Core/Model/Layout/Update.php on line 431″;i:1;s:2330:”#0 /home/…/public_html/…/app/code/core/Mage/Core/Model/Layout/Update.php(431): mageCoreErrorHandler(2, ‘simplexml_load_…’, ‘/home/zergant/p…’, 431, Array)
#1 /home/…/public_html/…/app/code/core/Mage/Core/Model/Layout/Update.php(273): Mage_Core_Model_Layout_Update->getFileLayoutUpdatesXml(‘fetchFileLayoutUpdates(‘adminhtml’, ‘default’, ‘skin_free’, ‘0’)
#3 /home/…/public_html/…/app/code/core/Mage/Core/Model/Layout/Update.php(246): Mage_Core_Model_Layout_Update->fetchPackageLayoutUpdates()
#4 /home/…/public_html/…/app/code/core/Mage/Core/Model/Layout/Update.php(224): Mage_Core_Model_Layout_Update->merge(‘default’)
#5 /home/…/public_html/…/app/code/core/Mage/Core/Controller/Varien/Action.php(305): Mage_Core_Model_Layout_Update->load(‘default’)
#6 /home/…/public_html/…/app/code/core/Mage/Core/Controller/Varien/Action.php(260): Mage_Core_Controller_Varien_Action->loadLayoutUpdates()
#7 /home/…/public_html/…/app/code/core/Mage/Adminhtml/Controller/Action.php(263): Mage_Core_Controller_Varien_Action->loadLayout()
#8 /home/…/public_html/…/app/code/core/Mage/Adminhtml/controllers/CacheController.php(46): Mage_Adminhtml_Controller_Action->loadLayout(NULL, true, true)
#9 /home/…/public_html/…/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_CacheController->indexAction()
#10 /home/…/public_html/…/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch()
#11 /home/…/public_html/…/app/code/core/Mage/Core/Controller/Varien/Front.php(177): Mage_Core_Controller_Varien_Router_Standard->match(‘index)
#12 /home/…/public_html/…/app/code/core/Mage/Core/Model/App.php(304): Mage_Core_Controller_Varien_Front->dispatch(Object(Mage_Core_Controller_Request_Http))
#13 /home/…/public_html/…/app/Mage.php(596): Mage_Core_Model_App->run()
#14 /home/…/public_html/…/index.php(78): Mage::run(Array)
#15 {main}”;s:3:”url”;s:66:”/index.php/admin/cache/index/key/0818460e3be0e710c50c3f22679aea85/”;s:11:”script_name”;s:10:”/index.php”;s:4:”skin”;s:5:”admin”;}
How גן I fix this problem?
Thanks,
Shani
thanks you this really helped me get my module to show up in the tab now i just have to figure out how to relate the content in my module to the product that is being veiwed
Hello,
I have added a tab according to the instruction given above..but i am really in need and urgent to show content when we click to the tab..
In my case when tab is clicked, I have to show a complete grid view of magento..
Please please respnse me ASAP.
Thanks in advance
Hi thanks for this article. I’ve tried this and recieved and error
a:5:{i:0;s:24:”Wrong tab configuration.”;i:1;s:1952:”#0 [internal function]: Mage_Adminhtml_Block_Widget_Tabs->addTab(‘module_tab’, ‘module/adminhtml_c…’)
I’m running Magento CE 1.7.0.2.
Can you help me how to do it in this version?
Thank you so much 🙂
Hello,
To add the tab, your Block has to implement Mage_Adminhtml_Block_Widget_Tab_Interface and override the all the functions that I mentioned in this tutorial. Please try it again. Hope you success!
Hi, nice quick and easy tutorial.
Just, when we have our new tab, how and where do me put a Varien_Data_Form in the content ?
Thanks a lot if you help me.
found it, sry for asking, was working on it for 3 days.
Solution : create the varian_data_form in the _prepareForm() but the class must extend Mage_Adminhtml_Block_Widget_Form instead of Mage_Core_Block_Template. Am I right ?
It’s so obvious now I have it in front of my eyes …
Hello Smoi,
Thanks for your comment. I think your block needs to extend Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface
and create Varien_Data_Form in _prepareForm() method.
Tell me if you have any other questions. 😉