5

I'm trying to add a custom tab to the new product page in the admin panel. The first block added my tab successfully to the product edit page. The second block definitely does add the tab to the new product page, but it seems to add it both before choosing the product type (where normally there is only one tab called settings that lets you choose the product type before proceeding) and after (when all product settings are made available to you, just like edit).

I really only want my tab on the part of the new product page after you choose a product type. I'll also ask if there's a way to specify whether the tab shows up on simple products, grouped products, configurables, etc. as this is something I may be interested in doing if it is a simple implementation. My main goal, however, is to remove the tab from the first step of new product creation, and only have the tab appear on the second step, no matter the product type.

If that didn't make sense or you're more visual, just take a look at this image, and see how silly it looks to have my new 'Related Projects' tab showing up here:

https://i.sstatic.net/HIPHr.jpg

It does, however, show up here where it should remain:

https://i.sstatic.net/LuRWT.jpg

<layout>
    <adminhtml_catalog_product_edit>
        <reference name="product_tabs">
            <action method="addTabAfter">
                <name>Related Projects</name>
                <block>company_module/adminhtml_catalog_product_tab</block>
                <after>related</after>
            </action>
        </reference>
    </adminhtml_catalog_product_edit>

    <adminhtml_catalog_product_new>
        <reference name="product_tabs">
            <action method="addTabAfter">
                <name>Related Projects</name>
                <block>company_module/adminhtml_catalog_product_tab</block>
                <after>related</after>
            </action>
        </reference>
    </adminhtml_catalog_product_new>
</layout>

Any help greatly appreciated!

2 Answers 2

5

Each tab must implement the interface Mage_Adminhtml_Block_Widget_Tab_Interface. This interface contains 4 methods. One of them is canShowTab.
you need to make that method look like this:

public function canShowTab() {
    $product = Mage::registry('current_product');
    if ($product->getId()) {
        return true;
    }
    if (!$product->getAttributeSetId()) {
        return false;
    }
    $request = Mage::app()->getRequest();
    if ($request->getParam('type') == 'configurable') {
        if ($request->getParam('attributes')) {
            return true;
        }
    }
    return false;
}
3
  • 1
    And in case you're curious how the default Magento tabs do this, take a look at Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs::_prepareLayout. It checks if the product has an attribute set ID yet. If not, it only adds the Settings tab. Otherwise, it adds the regular tabs (of which some have further conditions).
    – Agop
    Commented May 13, 2015 at 21:08
  • Do you have any idea about if product is on add or edit page ? Commented Jun 15, 2017 at 13:39
  • 1
    Mage::registry('current_product')->getId(). If it returns null you're on add. If it's a number you're on edit.
    – Marius
    Commented Jun 15, 2017 at 14:01
3

In case anyone is wondering how to display this in every tab, without regard for product type, this answer (based off of Agop's answer) will do that:

public function canShowTab()
{

    // Pull in our product
    $product = Mage::registry('current_product');

    // The request
    $request = Mage::app()->getRequest();

    // Show if we have a product already (edit product page)
    if ($product->getId()) {
        return true;
    }

    // Do not show if we don't have any attribute set
    if (!$product->getAttributeSetId()) {
        return false;
    }

    // If we do have an attribute set, it's okay to show (add new product page)
    if ($request->getParam('set')) {
            return true;
    }

    return false;

}

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.