Pergunta

I am trying to override core/catalog/block/product/List.php with following

Ref:http://www.magentocommerce.com/boards/viewthread/14692/

file: Ziva/Customcatalog/etc/config.xml

<config>
    <modules>
        <Ziva_CustomCatalog>
            <version>1.0.0</version>
        </Ziva_CustomCatalog>
    </modules>
    <global>
        <blocks>
            <catalog>
                <class>Ziva_CustomCatalog_Block</class> <!--this is a new block page for that custom module-->
                <rewrite>
                    <product_list>Ziva_Customcatalog_Block_Product_List</product_list>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

file: Ziva/Customcatalog/Block/Product/List.php

class Ziva_Customcatalog_Block_Product_List extends Mage_Catalog_Block_Product_List {

    public function __construct() {
        parent::__construct();
    }

    protected function _getProductCollection() { // trying to override this method
        echo __CLASS__;
        return parent::_getProductCollection();
    }

    public function holdthis() {
        echo __METHOD__;
    }

}

In exception log I am getting

exception 'Mage_Core_Exception' with message 'Invalid block type: Ziva_CustomCatalog_Block_Product_Compare_Sidebar' in C:\wamp\www\magento2\app\Mage.php:594

followed by

Invalid block type: Ziva_CustomCatalog_Block_Product_Price_Template
Invalid block type: Ziva_CustomCatalog_Block_Layer_View
Invalid block type: Ziva_CustomCatalog_Block_Category_View
Invalid block type: Ziva_CustomCatalog_Block_Product_List_Toolbar

And no products are displayed

EDIT:

I figured the problem

<class>Ziva_Customcatalog_Block</class>

Now I am rephrasing the question.

In a custom module you can only have one block class? But in core/catalog/block, we can see many.

Foi útil?

Solução

If you update your config.xml as follows, you should be able to add multiple unique handles:

<config>
    <modules>
        <Ziva_CustomCatalog>
            <version>1.0.0</version>
        </Ziva_CustomCatalog>
    </modules>
    <global>
        <blocks>
            <ziva_customcatalog>
                <class>Ziva_CustomCatalog_Block</class> <!--this is a new block page for that custom module-->
            </ziva_customcatalog>
            <catalog>
                <rewrite>
                    <product_list>Ziva_Customcatalog_Block_Product_List</product_list>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

You can then call 'ziva_customcatalog/layer_view' for your new block.

Outras dicas

Pay attention:

<product_list>Ziva_Customcatalog_Block_Product_List</product_list>

must be in one line without spaces! I became crazy to solve a similar problem!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top