6

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

1
  • FYI the classgroup <WP_Tipfix> is unnecessary unless you are creating block classes.
    – benmarks
    Commented Mar 5, 2012 at 13:06

2 Answers 2

9

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.

1
  • You also have to clear the cache if this does not work!
    – Black
    Commented Nov 16, 2018 at 12:36
3

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.

5
  • This solution could not have fixed the problem based on the OP's original code.
    – benmarks
    Commented Mar 5, 2012 at 13:07
  • @Ben - Please look closely into the config.xml file content, to find that there is no mention of any config node as well as no mention of modules node. So I provided this solution, and in fact, the OP has himself commented out that it solved his problem. So can you please tell me, as to what I have done wrong? Commented Mar 5, 2012 at 18:56
  • As you surmise in your edit, the rewritten classname would be resolved by the autoloader to WP/Tipfix/Block/Catalog/Product/View.php - so Max's answer is the correct solution, assuming the the OP was snipping the config for brevity. Also, version number and classgroup are entirely superfluous for rewrites.
    – benmarks
    Commented Mar 5, 2012 at 20:03
  • @Ben - What the OP posted in the config.xml file was not a snippet, but the full page source code, otherwise the OP would not have commented out in this link: stackoverflow.com/questions/9565715/…. Also, if you think that my post is wrong anywhere, then please mark it as wrong & you can go for delete. I will have no qualms about it. Commented Mar 6, 2012 at 6:04
  • My main point was that your solution did not address the incorrect file location. Moreover, the correct answer had been posted, yet the OP accepted your answer, so I wanted the comment there for posterity and for any person who'd already referred to your answer as authoritative.
    – benmarks
    Commented Mar 6, 2012 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.