2

I am trying to overwrite a magento's core block but it shows an error like this

Fatal error: Call to a member function addToChildGroup() on a non-object in /opt/lampp/htdocs/magento_new/app/code/core/Mage/Core/Block/Abstract.php on line 815

here is my modules config.xml

<?xml version="1.0"?>
<config>
<modules>
<Pfay_MyProduct>
    <version>1.0.0</version>
</Pfay_MyProduct>
</modules>
<global>
    <blocks>
        <catalog>
            <rewrite>
                 <product_view>Pfay_MyProduct_Block_Catalog_Product_View</product_view>
            </rewrite>
         </catalog>
    </blocks>
</global>
</config>

and my view.php is

<?php

class Pfay_MyProduct_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
    public function canEmailToFriend()
    {
            return false;
    }
}

What is wrong in this ?

2
  • Please try to override class as per answer and create the file as per the below path and name
    – Keyul Shah
    Commented Feb 4, 2014 at 15:14
  • 1
    I am not sure your block rewrite is connected to the error. The rewrite itself looks OK. Try to find all calls for addToChildGroup fucntion from layout XMLs and make sure their blocks types inherits from Mage_Core_Block_Abstract.
    – Itay Raz
    Commented Feb 4, 2014 at 15:16

1 Answer 1

1

Try Below code

In config.xml file

<?xml version="1.0"?>
 <config>
  <modules>
    <Pfay_MyProduct>
      <version>0.1.0</version>
    </Pfay_MyProduct>
  </modules>
  <global>        
    <blocks>
      <myproduct>
        <class>Pfay_MyProduct_Block</class>
      </myproduct>
        <catalog>
            <rewrite>
               <product_view>Pfay_MyProduct_Block_Catalog_Product_View</product_view>
            </rewrite>
        </catalog>
    </blocks>
  </global>
</config> 

And Crete file on Pfay\MyProduct\Block\Catalog\Product\View.php

<?php
class Pfay_MyProduct_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
   public function canEmailToFriend()
   {
      return false;
   }
}
7
  • Thanks Keyul for quick reply, I already tried this, but nothing happen, still got the error message
    – Waseem
    Commented Feb 4, 2014 at 15:26
  • have you flush your cache after installing this module?
    – Keyul Shah
    Commented Feb 4, 2014 at 15:29
  • yeah I flushed the cache but no luck
    – Waseem
    Commented Feb 4, 2014 at 15:30
  • where you put your code in local or core code pool?
    – Keyul Shah
    Commented Feb 4, 2014 at 15:31
  • chat.stackexchange.com/rooms/12842/with-waseem join this so we can discuss on chat
    – Keyul Shah
    Commented Feb 4, 2014 at 15:32

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.