user769154
user769154

Reputation: 227

Magento 1.5 override Catalog block

I'm tryin to override Mage/Catalog/Block/Product/Abstract.php .

Assume that my module named Abc.

Here is my app/etc/modules/Abc_Catalog.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Abc_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </Abc_Catalog>
    </modules>
</config>

Here is my code/local/Abc/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <blocks>
            <catalog>
                <rewrite><product_abstract>Abc_Catalog_Block_Product_Abstract</product_abstract></rewrite>
             </catalog>
        </blocks>
    </global>
</config>

Here is my code/local/Abc/Catalog/Product/Abstract.php

include_once "Mage/Catalog/Block/Product/Abstract.php";

class Abc_Catalog_Block_Product_Abstract extends Mage_Catalog_Block_Product_Abstract
{
  public function getAddToCartUrl($product, $additional = array())
    {
       echo 'here'; exit;

       /*if ($product->getTypeInstance(true)->hasRequiredOptions($product)) {
            if (!isset($additional['_escape'])) {
                $additional['_escape'] = true;
            }
            if (!isset($additional['_query'])) {
                $additional['_query'] = array();
            }
            $additional['_query']['options'] = 'cart';

            return $this->getProductUrl($product, $additional);
        }*/
        return $this->helper('checkout/cart')->getAddUrl($product, $additional);
    } 
}

But its doesn't work. What i'm doing wrong?

Upvotes: 0

Views: 1472

Answers (2)

Ricardo Martins
Ricardo Martins

Reputation: 5993

You can create a same folder/file structure for that abstract class you wish to override. i.e.: /local/Mage/Customer/Model/Address/Abstract.php and write that entire class exactly equal as the original (with all methods), and change what you need.

No additional .xml is required, only the file on the specified folder. But remember: when upgrading Magento maybe you need to review this file.

Upvotes: 0

Gabriel Spiteri
Gabriel Spiteri

Reputation: 4978

In Magento it is not possible to rewrite an Abstract block in the traditional way. Can't you rewrite the class that is extending the abstract one?

Upvotes: 1

Related Questions