1

I'm having trouble getting a new module to work. To begin with I just want to add an additional tab to the Product Edit screen in the adminhtml. I want this tab to show underneath the standard "Custom Options" tab. I have my module showing up in the Configuration > Advanced > Advanced > Disable Module output section.

So here's what I have, seen any mistakes?

Path : app\etc\modules\ns>_CustomerHistory.xml

<?xml version="1.0"?>

<config>
    <modules>
        <<ns>_CustomerHistory>
            <active>true</active>
            <codePool>local</codePool>
        </<ns>_CustomerHistory>
    </modules>
</config>

Path: app\code\local\\CustomerHistory\etc\config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <<ns>_CustomerHistory>
            <version>0.1.0</version>
        </<ns>_CustomerHistory>
    </modules>
    <global>
        <blocks>
            <CustomerHistory>
                <class><ns>_CustomerHistory_Block</class>
            </CustomerHistory>
        </blocks>
        <models>
            <CustomerHistory>
                <class><ns>_CustomerHistory_Model</class>
            </CustomerHistory>
        </models>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <CustomerHistory>
                    <file>CustomerHistory.xml</file>
                </CustomerHistory>
            </updates>
        </layout>
    </adminhtml>
</config>

Path : app\code\local\ns>\CustomerHistory\Block\Adminhtml\Product\Edit\Tab.php

<?php

class <ns>_CustomerHistory_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget 
implements Mage_Adminhtml_Block_Widget_Tab_Interface 
{
    public function canShowTab()
    {
        return true;
    }

    public function getTabLabel()
    {
        return $this->_('Custom Tab');
    }

    public function getTabTitle()
    {
        return $this->_('Custom Tab');
    }

    public function isHidden()
    {
        return false;
    }

    public function getTabUrl()
    {
        return $this->getUrl('*/*/customtab', array('_current' => true));
    }

    public function getTabClass()
    {
        return 'ajax';
    }
}

?>

Path : app\design\adminhtml\default\default\layout\CustomerHistory.xml

    <?xml version="1.0"?>
    <layout>
        <adminhtml_catalog_product_edit>
            <reference name="product_tabs">
                <block type="CustomerHistory/adminhtml_catalog_product_edit_tab" name="custom_tab" template="CustomerHistory/catalog/product/edit/tab.phtml" />
                <action method="addTab">
                    <name>Custom Tab</name>
                    <block>custom_tab</block>
                </action>
            </reference>
        </adminhtml_catalog_product_edit>
    </layout>

Path : app\design\adminhtml\default\default\template\CustomerHistory\catalog\product\edit\tab.phtml

<?php
/**
 * Custom tab template
 */
?>
<div>
    <h1>Hello</h1>
</div>

It goes without saying here, any help would be greatly appreciated!

Adam92
  • 436
  • 8
  • 23
  • Is your path for Tab.php correct? You wrote you have it in `Product\Tab.php` yet the classname is `Product_Edit_Tab`. – Jonathan Eltgroth May 25 '17 at 20:15
  • The path for Tab.php is app\code\local\\CustomerHistory\Block\Adminhtml\Product\Tab.php and my class name is "class _CustomerHistory_Block_Adminhtml_Catalog_Product_Edit_Tab". Is that wrong? What should it be? – Adam92 May 25 '17 at 20:22
  • Your class name has to match the path, so that file should be in `app\code\local\\CustomerHistory\Block\Adminhtml\Product\‌Edit\Tab.php`. This is one of the core rules of Magento class naming and file structure. – Jonathan Eltgroth May 25 '17 at 20:45
  • Obviously a mistake there! So I've made these changes and also changed the tab.phtml to match the path, but I'm still not getting the additional tab show in the Product Edit view. I've edited my question above to reflect these changes. – Adam92 May 26 '17 at 12:44
  • Have you tried clearing the cache? – Jay Ghosh May 26 '17 at 13:15
  • I've currently got cache disabled, but I've just flushed them for good practice and still no show. – Adam92 May 26 '17 at 13:32
  • Did you remove the template attribute from the block element in CustomerHistory.xml? Try adding `template="CustomerHistory\catalog\product\edit\tab.phtml"` after `name="..."` Just FYI, the template path does not need to match the class name or class path. You have a little more freedom in where you want to place template files in the directory strcuture. – Jonathan Eltgroth May 26 '17 at 19:22
  • Thanks @JonathanEltgroth, I've just added the template element but I still don't have the tab showing up. Again, I've added the changes above in the question. – Adam92 May 26 '17 at 19:41
  • Am I missing anything here? I'm still not getting the tab to display – Adam92 May 30 '17 at 19:22

0 Answers0