Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Overwriting a block
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Hi,

I am trying to overwrite a block, Mage_Catalog_Block_Product_View_Type_Simple.

I have created a new module in the local directory called Catalog which contains 2 directories: Block and etc.
In etc I have config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Company_Catalog>
            <
version>0.0.1</version>
        </
Company_Catalog>
    </
modules>
    <
blocks>
        <
catalog>
            <
rewrite>
                <
product_view_type_simple>Company_Catalog_Block_Product</product_view_type_simple>
            </
rewrite>
        </
catalog>
    </
blocks>
</
config>

And in Block i have Product.php :

class Company_Catalog_Block_Product extends Mage_Catalog_Block_Product_View_Type_Simple
{
  
public function getPriceHtml($product$displayMinimalPrice false$idSuffix=''$displayPromo true)
    
{
        
return $this->_getPriceBlock($product->getTypeId())
            ->
setTemplate($this->_getPriceBlockTemplate($product->getTypeId()))
            ->
setProduct($product)
            ->
setDisplayMinimalPrice($displayMinimalPrice)
            ->
setDisplayPromo($displayPromo)
            ->
setIdSuffix($idSuffix)
            ->
toHtml();
    
}
}

But nothing happens. Can anyone please help me.

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Damian Culotta
Enthusiast
 
Total Posts:  878
Joined:  2008-12-10
Argentina
 

Did you add the module xml file into /app/etc/modules ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Yes i have the Company_All.xml in module. Sorry i forgot to mention that.

<?xml version="1.0"?>

<config>
    <
modules>
        <
Company_Catalog>
      <
active>true</active>
      <
codePool>local</codePool>
    </
Company_Catalog>
    </
modules>
</
config>

I can see the module in Admin->System->Configuration->Advanced->Advanced as being enabled

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

This is working for my Module, perhaps try changing the tags around your block

<config>
  <
modules>
    <
Wdc_Catalog>
      <
version>0.1.0</version>
    </
Wdc_Catalog>
  </
modules>  
  <global>
    <
blocks>
      <
catalog>
        <
rewrite>
          <class>
Wdc_Catalog_Block</class>
        </
rewrite>
      </
catalog>
    </
blocks>
    <
models>
      <
catalog>
        <
rewrite>
          <class>
Wdc_Catalog_Model</class>
        </
rewrite>
      </
catalog>
    </
models>
  </global>
</
config>

Call it class instead

 
Magento Community Magento Community
Magento Community
Magento Community
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Thank you very much for the quick reply. But in your example i think you have overwrote the hole module catalog. All I need is one block, not all.
Although after a few tries i have found a way to get it working the problem was in the file config.xml from local/Company/Catalog/etc. It should be like this:

<?xml version="1.0"?>

<config>

    <
modules>
        <
Company_Catalog>
            <
version>0.0.1</version>
        </
Company_Catalog>
    </
modules>
    
<global>
    <
blocks>
        <
catalog>
            <
rewrite>
                <
product_view_type_simple>Company_Catalog_Block_Product</product_view_type_simple>
            </
rewrite>
        </
catalog>
    </
blocks>
</global>
    
</
config>

But now I have a new problem. I have discovered the overwriting the block Mage_Catalog_Block_Product_View_Type_Simple only helps me on the product details page but i need the getPriceHtml function to be changed also on the product listing page. To do that I need to overwrite the function from the Mage_Catalog_Block_Product_Abstract.

So i have modified the config.xml to :

<?xml version="1.0"?>

<config>

    <
modules>
        <
Company_Catalog>
            <
version>0.0.2</version>
        </
Company_Catalog>
    </
modules>
    
<global>
    <
blocks>
        <
catalog>
            <
rewrite>
                <
product_abstract>Company_Catalog_Block_Product</product_abstract>
            </
rewrite>
        </
catalog>
    </
blocks>
</global>
    
</
config>

also the Product.php from local/Company/Catalog/Block to:

class Company_Catalog_Block_Product extends Mage_Catalog_Block_Product_Abstract
{
  
public function getPriceHtml($product$displayMinimalPrice false$idSuffix=''$displayPromo true)
    
{
        
return $this->_getPriceBlock($product->getTypeId())
            ->
setTemplate($this->_getPriceBlockTemplate($product->getTypeId()))
            ->
setProduct($product)
            ->
setDisplayMinimalPrice($displayMinimalPrice)
            ->
setDisplayPromo($displayPromo)
            ->
setIdSuffix($idSuffix)
            ->
toHtml();
    
}
}

and i’m kind of back to my original problem that nothing happens.

So can anyone please explain me what am i doing wrong.

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I ran into the problem recently with Case sensitivity on the Linux server.

Are you sure all your directories and file names are the correct case?

Just a thought.

 
Magento Community Magento Community
Magento Community
Magento Community
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Thank you for the reply.

I think my custom directories and files are ok. I mean they worked for overwriting the the block Mage_Catalog_Block_Product_View_Type_Simple and the only difference between are in local/Company/Catalog/etc/config.xml:

<product_abstract>Company_Catalog_Block_Product</product_abstract>
instead of
<product_view_type_simple>Company_Catalog_Block_Product</product_view_type_simple>

and in local/Company/Catalog/Block/Product.php:

class Company_Catalog_Block_Product extends Mage_Catalog_Block_Product_Abstract
instead of
class Company_Catalog_Block_Product extends Mage_Catalog_Block_Product_View_Type_Simple

The rest it’s the same.

Thank you again for your help and please write any ideas or suggestions you have. I’m running out of places to ask for help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mChelevich
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2009-03-31
 

Yes, there’re problems to rewrite abstract classes (models as for me)
Please correct me if I’m wrong, Mage_Catalog_Block_Product_View_Type_Simple is a child of Mage_Catalog_Block_Product_Abstract ?
So, try to rewrite abstract parent class and its child and extend them both.
Smth like this:

<product_abstract>Company_Catalog_Block_Abstract</product_abstract>
<product_view_type_simple>Company_Catalog_Block_Product</product_view_type_simple>

local/Company/Catalog/Block/Product.php:
class Company_Catalog_Block_Product extends Company_Catalog_Block_Abstract { ... }

local/Company/Catalog/Block/Abstract.php:
class Company_Catalog_Block_Abstract extends Mage_Catalog_Block_Product_Abstract { ... }

 
Magento Community Magento Community
Magento Community
Magento Community
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Thank you for the reply. I’m sorry I’m answering so late.

I don’t want to overwrite both blocks. I only want now to overwrite the Mage_Catalog_Block_Product_Abstract. The problem is the it worked when I tried to overwrite the Mage_Catalog_Block_Product_View_Type_Simple and now it doesn’t work for Mage_Catalog_Block_Product_Abstract although I’m using the same syntax.

Please excuse my english.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Xavier Naud
Jr. Member
 
Total Posts:  1
Joined:  2009-11-30
 

Hi,

Any updates on this thread?
I hit the same issue.

Thanks

Xavier

 
Magento Community Magento Community
Magento Community
Magento Community
 
M. Calin
Jr. Member
 
Total Posts:  9
Joined:  2009-04-15
 

Unfortunately I didn’t find any answer for this. If you can find one please tell me also, I am still interested.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aflg
Jr. Member
 
Total Posts:  3
Joined:  2010-07-17
 

Not promising: How do I overwrite/extend an abstract class?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top