1

I'm trying to develop a module which will hide selected product edit tabs for a particular user role when they are logged into the administration panel (Catalog> Products< Edit).

I have the code below, and I can tell the module is active but the module is having no affect at the moment and I'm not sure where I am going wrong.

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <tww_RemoveProductTabs>
            <version>0.1.0</version>
        </tww_RemoveProductTabs>
    </modules>
    <global>
        <models>
            <tww_RemoveProductTabs>
                <class>tww_RemoveProductTabs_Model</class>
            </tww_RemoveProductTabs>
        </models>
        <events>
            <core_block_abstract_prepare_layout_after>
                <observers>
                    <tww_RemoveProductTabs>
                        <class>tww_RemoveProductTabs/observer</class>
                        <method>removeTabs</method>
                        <type>singleton</type>
                    <tww_RemoveProductTabs>
                </observers>
            </core_block_abstract_prepare_layout_after>
        </events>
    </global>
</config>

tww_RemoveProductTabs.xml

<?xml version="1.0"?>
<config>
    <modules>
        <tww_RemoveProductTabs>
            <active>true</active>
            <codePool>local</codePool>
        </tww_RemoveProductTabs>
    </modules>
</config>

Observer.php

<?php
class tww_RemoveProductTabs_Model_Observer
{
    public function removeTabs(Varien_Event_Observer $observer)
    {
        // Get the users role id
        $admin_user_session = Mage::getSingleton('admin/session');
        $adminuserId = $admin_user_session->getUser()->getUserId();
        $role_data = Mage::getModel('admin/user')->load($adminuserId)->getRole()->getData();

        // if lower admin user
        if($role_data == 4)
        {
            $tabBlock = $evt->getEvent()->getBlock();

            if ($tabBlock instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs) 
            {
                $tab_ids = $tabBlock->getTabsIds();
                $tabs_to_hide = array('inventory');

                foreach ($tab_ids as $tab)
                {
                    if(in_array($tab, $tabs_to_hide))]
                    {
                        $tabBlock->removeTab($tab);
                    }
                    else
                    {
                        $tabBlock->setActiveTab($tab);
                    }
                }
            }
            // tesing
            $tabBlock->removeTab('related');
        }
    }
}

Any ideas would be greatly appreciated. Thanks.

  • @sv3n it is not duplicate, that question was asked later than this one – Piyush Mar 21 '18 at 12:23
  • @Piyush does it matter which one is older? It's the same question - just for product page. – sv3n Mar 21 '18 at 12:35
  • @sv3n IMHO it will be unfair with questioner, it is better to mark the question duplicate which is asked later – Piyush Mar 21 '18 at 12:39
0

app\etc\modules\Tww_Removeproducttabs.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Tww_Removeproducttabs>
            <active>true</active>
            <codePool>local</codePool>
        </Tww_Removeproducttabs>
    </modules>
</config>

app\code\local\Tww\Removeproducttabs\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Tww_Removeproducttabs>
            <version>0.1.0</version>
        </Tww_Removeproducttabs>
    </modules>
    <global>
        <models>
            <removeproducttabs>
                <class>Tww_Removeproducttabs_Model</class>
            </removeproducttabs>
        </models>
        <events>
            <adminhtml_block_html_before>
                <observers>
                    <tww_removeproducttabs>
                        <type>singleton</type>
                        <class>removeproducttabs/observer</class>
                        <method>removeTabs</method>
                    </tww_removeproducttabs>
                </observers>
            </adminhtml_block_html_before>
        </events>
    </global>
</config>

Tww_Removeproducttabs_Model_Observer

<?php
class Tww_Removeproducttabs_Model_Observer
{
    public function removeTabs(Varien_Event_Observer $observer)
    {
        echo 111;die;
    }
}
?>
  • Hi Abdul, I've changed to the <adminhtml_block_html_before> at Im still not having any success. I've added a Mage::log("Test"); just after the if statement and I'm not getting an entry into the log files. – Adam92 Nov 30 '15 at 9:55
  • have you added file app\etc\modules\Tww_Removeproducttabs.xml? – Abdul Nov 30 '15 at 9:58
  • Hi Abdul, yes, and I am able to see the module in the disable module output in the configuration as active. Thanks for you help! – Adam92 Nov 30 '15 at 10:51
  • now working your module? – Abdul Nov 30 '15 at 10:54
  • Hi Abdul, unfortunately not - I'm still not getting any entries into the log file either - I dont think my observer is triggering? Thanks. – Adam92 Nov 30 '15 at 11:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.