Magento – Changing default tab order in admin Product Information

adminadminhtmlmagento-1.8

I wish to change the default order of tabs in Product Information when adding a new product. I want to put the Categories tab beneath the General tab (or even above it) – like here:

tab order

I'm struggling to figure out how to do this, as the majority of guides deal with custom tabs and thus allow you to use the after tags in the layout.xml file. From what I have found, editing the Tabs.php (app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php) file is recommended by some – however; I tried to do this and it had no effect. Making the below code modification should have put the Catalog tab above the Inventory tab, but didn't:

$this->addTab('categories', array(
                'label'     => Mage::helper('catalog')->__('Categories'),
                'url'       => $this->getUrl('*/*/categories', array('_current' => true)),
                'class'     => 'ajax',
            ));

if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) {
                $this->addTab('inventory', array(
                    'label'     => Mage::helper('catalog')->__('Inventory'),
                    'content'   => $this->_translateHtml($this->getLayout()
                        ->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()),
                ));

(I know it's not ideal to edit core files, but I just wanted to test it.)

In any case, because I want the Categories tab beneath the General tab, I would need to edit this for loop which retrieves the user configurable tabs first no?

foreach ($groupCollection as $group) {
                $attributes = $product->getAttributes($group->getId(), true);
                // do not add groups without attributes

                foreach ($attributes as $key => $attribute) {
                    if( !$attribute->getIsVisible() ) {
                        unset($attributes[$key]);
                    }
                }

                if (count($attributes)==0) {
                    continue;
                }

                $this->addTab('group_'.$group->getId(), array(
                    'label'     => Mage::helper('catalog')->__($group->getAttributeGroupName()),
                    'content'   => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
                        'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                            ->setGroupAttributes($attributes)
                            ->toHtml()),
                ));
            }

Any suggestions? Thanks!

Best Answer

So it turns out that app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php is the correct file. I or someone else had copied it to the local directory so that copy was being used instead. Moving the categories tab above the inventory tab via manipulating their order in the code did work. I was also able to follow this guide:

http://www.netismine.com/magento/change-tab-order-in-product-admin

To hide my Additional Fields tab, then copy the code and reinclude the tab beneath the Categories tab, so that Categories appeared second. I also commented out the Up-sells etc tabs as I have no use of them.

If it helps, here is the code from the edits.php tab down to the Inventory tab:

protected function _prepareLayout()
{
    $product = $this->getProduct();

    if (!($setId = $product->getAttributeSetId())) {
        $setId = $this->getRequest()->getParam('set', null);
    }

    if ($setId) {
        $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->setAttributeSetFilter($setId)
            ->setSortOrder()
           ->addFieldToFilter('attribute_group_id',array('nin'=>array('27'))) // using 'in' instead of 'nin' will only return these tabs
            ->load();

        foreach ($groupCollection as $group) {
            $attributes = $product->getAttributes($group->getId(), true);
            // do not add groups without attributes

            foreach ($attributes as $key => $attribute) {
                if( !$attribute->getIsVisible() ) {
                    unset($attributes[$key]);
                }
            }

            if (count($attributes)==0) {
                continue;
            }

            $this->addTab('group_'.$group->getId(), array(
                'label'     => Mage::helper('catalog')->__($group->getAttributeGroupName()),
                'content'   => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
                    'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                        ->setGroupAttributes($attributes)
                        ->toHtml()),
            ));
        }

        $this->addTab('categories', array(
            'label'     => Mage::helper('catalog')->__('Categories'),
            'url'       => $this->getUrl('*/*/categories', array('_current' => true)),
            'class'     => 'ajax',
        ));

        $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->setAttributeSetFilter($setId)
            ->setSortOrder()
           ->addFieldToFilter('attribute_group_id',array('in'=>array('27'))) // using nin hides that tab id
            ->load();

        foreach ($groupCollection as $group) {
            $attributes = $product->getAttributes($group->getId(), true);
            // do not add groups without attributes

            foreach ($attributes as $key => $attribute) {
                if( !$attribute->getIsVisible() ) {
                    unset($attributes[$key]);
                }
            }

            if (count($attributes)==0) {
                continue;
            }

            $this->addTab('group_'.$group->getId(), array(
                'label'     => Mage::helper('catalog')->__($group->getAttributeGroupName()),
                'content'   => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
                    'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                        ->setGroupAttributes($attributes)
                        ->toHtml()),
            ));
        }

        $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->setAttributeSetFilter($setId)
            ->setSortOrder()
           ->addFieldToFilter('attribute_group_id',array('in'=>array('27'))) // using 'in' only returns this tab ID
            ->load();

        if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) {
            $this->addTab('inventory', array(
                'label'     => Mage::helper('catalog')->__('Inventory'),
                'content'   => $this->_translateHtml($this->getLayout()
                    ->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()),
            ));
        }
Related Topic