Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Rewrite Block is not working

I try to rewrite core file from magento. Somehow it does not overwrite the code. I try to overwrite the function getProduct().

Tipfix/Block/Product/View.php

<?php

class WP_Tipfix_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{

    public function getProduct()
    {

        if (!Mage::registry('product') && $this->getProductId()) {
            $product = Mage::getModel('catalog/product')->load($this->getProductId());
            Mage::register('product', $product);
        }

        //return Mage::registry('product');
    }
}

Tipfix/etc/config.xml

<blocks>
    <WP_Tipfix>
        <class>WP_Tipfix_Block</class>
    </WP_Tipfix>
    <catalog>
        <rewrite>
            <product_view>WP_Tipfix_Block_Catalog_Product_View</product_view>
        </rewrite>
    </catalog>
</blocks>

I have know idea what i'm doing wrong.

Gr. Lex

like image 260
Lexperts Avatar asked Mar 05 '12 11:03

Lexperts


Video Answer


2 Answers

Your class is WP_Tipfix_Block_Catalog_Product_View which means it must be in the folder WP/Tipfix/Block/Catalog/Product/View.php. You must either move your Product directory into a new directory called Catalog in that place or rename your class (both the class and in the XML) to WP_Tipfix_Block_Product_View. I recommend moving the file.

like image 113
Max Avatar answered Nov 12 '22 07:11

Max


Please change the config.xml content of your module to this, and I'm sure that it should work:-

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <WP_Tipfix>
            <version>1.0.0</version>
        </WP_Tipfix>
    </modules>

    <global>
        <blocks>
            <wptipfix>
                <class>WP_Tipfix_Block</class>
            </wptipfix>

            <catalog>
                <rewrite>
                    <product_view>WP_Tipfix_Block_Catalog_Product_View</product_view>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

Hope it helps.


UPDATE:- After Ben's comment, I feel that I should have mentioned that the OP must also use the solution as mentioned by Max in his answer. So the OP will need a combined effort to fix his problem.

like image 34
Knowledge Craving Avatar answered Nov 12 '22 06:11

Knowledge Craving