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

Lexperts
  • 353
  • 2
  • 7
  • 19

2 Answers2

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.

Knowledge Craving
  • 7,955
  • 13
  • 49
  • 92
Max
  • 8,671
  • 4
  • 33
  • 46
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.

Community
  • 1
  • 1
Knowledge Craving
  • 7,955
  • 13
  • 49
  • 92
  • This solution *could not* have fixed the problem based on the OP's original code. – benmarks Mar 05 '12 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?** – Knowledge Craving Mar 05 '12 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 Mar 05 '12 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: http://stackoverflow.com/questions/9565715/magento-rewrite-block-is-not-working/9566649#comment-12127732. **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.** – Knowledge Craving Mar 06 '12 at 06: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 Mar 06 '12 at 12:57