4

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.

  • If you only want to add things to the collection I recommend to implement an observer and listen to catalog_block_product_list_collection – Fabian Blechschmidt Nov 13 '13 at 11:41
  • @FabianBlechschmidt: I am trying to limit the number of items in collection. I tried ->setPageSize(10) but it is not resetting the filters according to the loaded items. It is showing the original filters of the entire collection – zamil Nov 13 '13 at 11:56
6

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.

0

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!

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.