0

I want to create tab in product edit area in magento, here is the code I and using but the tab is not added. Can someone check and tell me whats the problem ?

Emizentech_Nutriprof

config.xml-

<?xml version="1.0"?>
<config>
  <modules>
    <Emizentech_Nutriprof>
      <version>0.0.1</version>
    </Emizentech_Nutriprof>
  </modules>

  <global>
      <blocks>
        <nutriprof>Emizentech_Nutriprof_Block</nutriprof>
      </blocks>
      <helpers>
        <nutriprof>
          <class>Emizentech_Nutriprof_Helper</class>
        </nutriprof>
    </helpers>
  </global>

  <adminhtml>
    <layout>
      <updates>
        <nutriprof>
          <file>nutriprof.xml</file>
        </nutriprof>
      </updates>
    </layout>
  </adminhtml>

    <admin>
      <routers>
        <adminhtml>
          <args>
            <modules>
              <nutriprof before="Mage_Adminhtml">Emizentech_Nutriprof_Adminhtml</nutriprof>
            </modules>
          </args>
        </adminhtml>
      </routers>
    </admin>

</config> 

Emizentech/Nutriprof/Block/Adminhtml/Catalog/Product/Tab.php-

<?php

class Emizentech_Nutriprof_Block_Adminhtml_Catalog_Product_Tab extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
    mage::log("hi",null,"bye.log");
    public function _construct(){
        parent::_construct();
        $this->setTemplate('nutriprof/catalog/product/tab.phtml')
    }
    public function getTabLabel(){
        return $this->('My Customt Tabs');
    }
    public function getTabTitle(){
        return $this->__('Click here to view your custom tab content');
    }
    public function canShowTab(){
        return true;
    }    
}

?>

app/design/adminhtml/default/default/layout/nutriprof.xml-

<?xml version="1.0"?>
<layout>
    <adminhtml_catalog_product_edit>
        <reference name="paroduct_tabs">
            <action method="addTab">
                <name>nutriprof</name>
                <block>nutriprof/adminhtml_catalog_product_tab</block>
            </action>
        </reference>
    </adminhtml_catalog_product_edit>
</layout>

app/design/adminhtml/default/default/template/nutriprof/catalog/product/tab.phtml-

<div>
  <h1>hello</h1>
</div>
1

Change your config.xml


<?xml version="1.0"?>
<config>
    <modules>
        <Emizentech_Nutriprof>
            <version>0.0.1</version>
        </Emizentech_Nutriprof>
    </modules>
    <global>
        <blocks>
            <nutriprof>
                <class>Emizentech_Nutriprof_Block</class>
            </nutriprof>
        </blocks>
        <helpers>
            <nutriprof>
                <class>Emizentech_Nutriprof_Helper</class>
            </nutriprof>
        </helpers>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <nutriprof>
                    <file>nutriprof.xml</file>
                </nutriprof>
            </updates>
        </layout>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <nutriprof before="Mage_Adminhtml">Emizentech_Nutriprof_Adminhtml</nutriprof>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Change your tab class [Emizentech/Nutriprof/Block/Adminhtml/Catalog/Product/Tab.php]


class Emizentech_Nutriprof_Block_Adminhtml_Catalog_Product_Tab extends Mage_Adminhtml_Block_Template
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
    /**
     * Set the template for the block
     *
     */
    public function _construct()
    {
        parent::_construct();
        $this->setTemplate('nutriprof/catalog/product/tab.phtml');
    }

    /**
     * Retrieve the label used for the tab relating to this block
     *
     * @return string
     */
    public function getTabLabel()
    {
        return $this->__('My Custom Tabs');
    }

    /**
     * Retrieve the title used by this tab
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->__('Click here to view your custom tab content');
    }

    /**
     * Determines whether to display the tab
     * Add logic here to decide whether you want the tab to display
     *
     * @return bool
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Stops the tab being hidden
     *
     * @return bool
     */
    public function isHidden()
    {
        return false;
    }


}

Change your layout xml config [app/design/adminhtml/default/default/layout/nutriprof.xml]


<?xml version="1.0"?>
<layout>
    <adminhtml_catalog_product_edit>
        <reference name="product_tabs">
            <action method="addTabAfter">
                <name>nutriprof</name>
                <block>nutriprof/adminhtml_catalog_product_tab
                <after>downloadable_items</after>
            </action>
        </reference>
    </adminhtml_catalog_product_edit>
</layout>

Clear cache

  • Thanks for the answer but not working. I placed die('hello'); in file 'Tab.php' but it didn't show anything. – Shashank Kumrawat Jun 8 '17 at 6:19
  • It's tested code and it's working fine. Did you clear cache? OR Share your module. – Sohel Rana Jun 8 '17 at 7:31
  • Thanks Sohel for your answer, I really appreciate it. I dont know why my code was not working. then I found this link ,followed it and it worked. fishpig.co.uk/magento/tutorials/… – Shashank Kumrawat Jun 8 '17 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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