2

I am developing social network project in magento, so i like to remove the all product related things from the magento admin.

How to remove the "category product" from the category edit page.enter image description here

1 Answer 1

3

You can remove a tab using the method Mage_Adminhtml_Block_Widget_Tabs::removeTab(). Every edit page in Magento (admin side) is actually child block of Mage_Adminhtml_Block_Widget_Tabs block class.

In this case, mean in category edit page, the child block responsible for the category edit page is Mage_Adminhtml_Block_Catalog_Category_Tabs. You need to look into the method _prepareLayout() method there. You can see this code there.

 protected function _prepareLayout()
 {
     ...
     $this->addTab('products', array(
        'label'     => Mage::helper('catalog')->__('Category Products'),
        'content'   => $this->getLayout()->createBlock(
            'adminhtml/catalog_category_tab_product',
            'category.product.grid'
        )->toHtml(),
    ));

    // dispatch event add custom tabs
    Mage::dispatchEvent('adminhtml_catalog_category_tabs', array(
        'tabs'  => $this
    ));
    ...
 }

The first part is adding the product tab in the edit page. So the solution is removing this part from this method. However you should remove that part in "Magento way"

You are lucky, the second part gives a clear provision to remove the product tab. ie it registers an event adminhtml_catalog_category_tabs. So what you need to do is define a module which observe the above event and remove the product tab.

Below I will show you the important part of the custom extension. I am going to call this module as Rkt_RemoveCategoryTab.

File : app\code\community\Rkt\RemoveCategoryTab\etc\config.xml

<config>
    <modules>
        <Rkt_RemoveCategoryTab>
            <version>1.0.0</version>
        </Rkt_RemoveCategoryTab>
    </modules>
    <global>
        <models>
            <rkt_removecategorytab>
                <class>Rkt_RemoveCategoryTab_Model</class>
            </rkt_removecategorytab>
        </models>
    </global>
    <adminhtml>
        <events>
            <adminhtml_catalog_category_tabs>
                <observers>
                    <remove_category_product_tab_from_edit_page>
                        <class>rkt_removecategorytab/observer</class>
                        <method>removeUnwantedCategoryTabs</method>
                    </remove_category_product_tab_from_edit_page>
                </observers>
            </adminhtml_catalog_category_tabs>
        </events>
   </adminhtml>
</config>

This the configuration file of our module. It just registers an observer for listening to the event adminhtml_catalog_category_tabs.

File : app\code\community\Rkt\RemoveCategoryTab\Model\Observer.php

class Rkt_RemoveCategoryTab_Model_Observer
{
    const CATEGORY_PRODUCT_TAB_ID = 'products';

    public function removeUnwantedCategoryTabs(Varien_Event_Observer $observer)
    {
        $tabs = $observer->getEvent()->getTabs();
        $tabs->removeTab(self::CATEGORY_PRODUCT_TAB_ID);
        return $this;
    }
}

Here as you can see, we are removing the product tab using it's tab id.

That's it. You are done. Now clear the cache and load the page again. You will see that the tab will get disappeared.

Rkt_RemoveCategoryTab Extension

For the sake of better understanding and for the reference, I have created an extension for this. Have a look on the extension which is available in my github account. You are free to use and modify it. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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