Catalog Blocks – Extend Core Product List Block Model

blockscatalogoverrides

I want to extend pring a function into magento where I assemble some product data.

In the end I want to call a function like $this->getAlternateTitle() within Lists and Products.

This is what I have:
app/etc/modules/Namespace_Name.xml

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

then I'm making the config in app/code/local/Namespace/Catalog/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Catalog>
            <version>0.0.1</version>
        </Namespace_Catalog>
    </modules>
    <global>
        <blocks>
                <class>Namespace_Catalog_Block_Product_List</class>
        </blocks>
    </global>
</config>

And finally defining the function here:
app/code/local/Namespace/Module/Block/Product/List.php

<?php

class Namespace_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List {
    public function makeBlue() {
     echo "Blueberrys are colorful";
    }
}

I am only getting back: Invalid method Mage_Catalog_Block_Product_List::makeBlue

What do I do wrong here? It's my first magento-function so please be kind with me 😉

Best Answer

config.xml

  <global>

    <blocks>

            <catalog>
                <rewrite>
                    <product_list>Namespace_Catalog_Block_Catalog_Product_List</product_list>
                <product_view>Namespace_Catalog_Block_Catalog_Product_View</product_view>
                </rewrite>
            </catalog>

    </blocks>
  </global>

Write class :

app/code/local/Namespace/Catalog/Block/Catalog/Product/List.php

<?php
class Namespace_Catalog_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_List
{
}

app/code/local/Namespace/Catalog/Block/Catalog/Product/view.php

<?php
class Namespace_Catalog_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
}
Related Topic