0

When i try to override "app\code\core\Mage\Adminhtml\Block\Catalog\Category\Tab" this Block Mage_Adminhtml_Block_Catalog_Category_Tab_Product for add new column in category product listing tab

I have get this error

Fatal error: Call to a member function toHtml() on a non-object in D:\xampp\htdocs\magento_new\app\code\core\Mage\Adminhtml\Block\Catalog\Category\Tabs.php on line 153

My code

Module config xml app\code\local\Krp\Adminhtml\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Krp_Adminhtml>
            <version>0.1</version>
        </Krp_Adminhtml>
    </modules>

    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_category_tab_product>Krp_Adminhtml_Block_Catalog_Category_Tab_Product</catalog_category_tab_product>
                </rewrite>
            </adminhtml>            
        </blocks>
    </global>    
</config>

app\etc\modules\Krp_Adminhtml.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Krp_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
        </Krp_Adminhtml>
    </modules>
</config>

Block file code app\code\local\Krp\Adminhtml\Block\Catalog\Category\Tab\Product.php

class Krp_Adminhtml_Block_Catalog_Category_Tab_Product extends Mage_Adminhtml_Block_Catalog_Category_Tab_Product{

   protected function _prepareCollection(){
    //=============== Code ==================//
   }

}
  • it means the rewrite works but it can't instantiate the new class. Can you post the full Krp_Adminhtml_Block_Catalog_Category_Tab_Product? It might be a PHP error in the class – Sander Mangel Jun 23 '15 at 14:37
1

You forgot to configure the name of the block class.

config.xml

    <config>
    ...
        <global>
        ...
            <blocks>
                <krp_adminhtml>
                    <class>Krp_Adminhtml_Block</class>
                </krp_adminhtml>

                <adminhtml>
                    <rewrite>
                        <catalog_category_tab_product>Krp_Adminhtml_Block_Catalog_Category_Tab_Product</catalog_category_tab_product>
                    </rewrite>
                </adminhtml>
            </blocks>
        ...
        </global>
    ...
    </config>

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.