1

I am trying to extend the Mage_Catalog_Block_Product_View class in app/core/Mage/Catalog/Block/Product/View.php

To do that I declared a new module in app/etc/modules/Fkoessler_myProduct.xml:

<config>
  <modules>
    <Fkoessler_MyProduct>
      <active>true</active>
      <codepool>local</codepool>
    </Fkoessler_MyProduct>
  </modules>
</config>

I created a app/code/local/Fkoessler/MyProduct/Block/Product/View.php file:

<?php
class FKoessler_MyProduct_Block_Product_View extends Mage_Catalog_Block_Product_View
{
    protected function _prepareLayout(){}
}

and finally I created the app/code/local/Fkoessler/MyProduct/etc/config.xml file:

<config>
    <modules>
        <Fkoessler_MyProduct>
            <version>0.1</version>
        </Fkoessler_MyProduct>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_view>Fkoessler_MyProduct_Block_Product_View</product_view>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

However it doesn't seem to be taken into account: the product view page still uses the prepareLayout as defined in the Magento core class.

What am I doing wrong?

0

There are simple few issues in config.

<rewrite is not close it should be <rewrite> in config.xml

and codepool should be codePool(p should be P) at Fkoessler_myProduct.xml

 <blocks>
            <catalog>
                <rewrite
                    <product_view>Fkoessler_MyProduct_Block_Product_View</product_view>
                </rewrite>
            </catalog>
        </blocks>

should be .....

    <blocks>
    <catalog>
        <rewrite>
            <product_view>Fkoessler_MyProduct_Block_Product_View</product_view>
        </rewrite>
    </catalog>
</blocks>

Module location is wrong:

it should be

app/code/local/(code folder is missing)
  • The <rewrite> was properly closed in my code and was a typo in this question, so I edited the question. I changed <codepool> to <codePool> but the custom class still isn't being used. Finally, I'm not sure what I'm supposed to fix in config.xml? Identation? – fkoessler Jun 9 '15 at 11:51
0

I would recommend you to enable developer mode first and see the logs also checking if you have defined <blocks>modulename>class>Yournamespace_yourmodule_Block</class></modulename></blocks>in your config.xml and case sensitive issue

0

Here is how I finally managed to use my own code. The problem was in the FKoessler_MyProduct_Block_Product_View class itself.

When I extend Mage_Catalog_Block_Product_View and redefine its _prepareLayout() method, it is still the _prepareLayout() method from the Mage_Catalog_Block_Product_View class that gets used. That is what was confusing me.

So I changed to extends Mage_Catalog_Block_Product_Abstract, copied the whole Mage_Catalog_Block_Product_View class code in my FKoessler_MyProduct_Block_Product_View class and applied customizations. And it's working fine like that.

class FKoessler_MyProduct_Block_Product_View extends Mage_Catalog_Block_Product_Abstract
{
   // copy code from Mage_Catalog_Bliock_Product_View in here
   // and customize to your needs
}

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.