The Product edit section (Catalog->Manage Products -> edit) I want to display only the Inventory tab for a particular admin user role.
For instance an admin user with "test" as user role should only see Inventory tab while trying to edit a product.
Currently I use core_block_abstract_prepare_layout_after
event to add a custom tab.
My observer function is as follows:
public function addTestBlock($observer){
$block = $observer->getEvent()->getBlock();
$product = Mage::registry('product');
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs && $this->_canAddTab($product)){
$block->addTab('myentity', array(
'label' => Mage::helper('mymodule')->__('Test'),
'url' => Mage::helper('adminhtml')->getUrl('adminhtml/marketplace_tendor_catalog_product/tendors', array('_current' => true)),
'class' => 'ajax',
));
}
return $this;
}
I have planned to use
adminhtml_catalog_product_edit_prepare_form
event to display only the "Inventory" tab for test admin user.
- Can I do this using event observer?
- If yes, How?
Can anyone guide me pls?
[EDIT: ]
as suggested by mpaepper I used controller_action_layout_generate_blocks_after
event and my observer function was like below:
public function vendorLayout($evt){
$tabBlock =$evt->getEvent()->getBlock('product_tabs');
$tab_ids = $tabBlock->getTabsIds();
foreach ($tab_ids as $tab){
if($tab != 'inventory'){
$tabBlock->removeTab($tab);
}
}
}
- checking the user role is not a problem I can add it later.
- removing the "General" tab results in the following.
- If i allow "General" (group_4) and "Inventory" (inventory) tabs, then it's working fine, but the requirement is only to display Inventory tab.
nothing happens if I click on that tab, I think the js script isn't loading.
what am i doing wrong?
Best Answer
I used
core_block_abstract_prepare_layout_after
event and the observer was as follows:first condition removes all the tabs but "inventory", second condition removes all buttons but "save".
Thanks to @mpaepper and @Alex.