Elavarasan
Elavarasan

Reputation: 2669

magento model class rewrite issue

I'm using magento enterprise edition 1.14.2. I want to rewrite the following class and function.

Mage_Catalog_Model_Product_Url

 public function formatUrlKey($str)
    {
        $urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));
        $urlKey = strtolower($urlKey);
        $urlKey = trim($urlKey, '-');

        return $urlKey;
    }

This is my rewrite module config file,

<?xml version="1.0"?>
<config>
  <modules>
    <Mypackage_Mymodule>
      <version>0.1.0</version>
    </Mypackage_Mymodule>
  </modules>
  <global>
    <helpers>
      <mymodule>
        <class>Mypackage_Mymodule_Helper</class>
      </mymodule>
    </helpers>
    <models>
      <mymodule>
        <class>Mypackage_Mymodule_Model</class>
        <resourceModel>mymodule_mysql4</resourceModel>
      </mymodule>
            <catalog>
                <rewrite>
                    <product_url>Mypackage_Mymodule_Model_Catalog_Product_Url</product_url>
                </rewrite>
            </catalog>
    </models>
  </global>
</config> 

And this my class,

app/code/local/Mypackage/Mymodule/Model/Catalog/Product

class Mypackage_Mymodule_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url
{
    public function formatUrlKey($str)
    {
//my stuffs
}
}

I think every thing seems fine. But I cant rewrite this class. But the same class extended in enterprise section in following class,

Enterprise_Catalog_Model_Product_Url

So that's why it is not working ..? If I extend this class then I can access that function

public function formatUrlKey($str)
        {
    //my stuffs
    }

Any solution or hints would be helpful for me ..

Upvotes: 1

Views: 267

Answers (2)

Rehan Mobin
Rehan Mobin

Reputation: 552

You need to extend and override this form Enterprise Now in your module config file replace

<catalog>
  <rewrite>
     <product_url>Mypackage_Mymodule_Model_Catalog_Product_Url</product_url>
   </rewrite>
</catalog>

with

<enterprise_catalog>
            <rewrite>
                <product_url>Mypackage_Mymodule_Model_Catalog_Product_Url</product_url>
            </rewrite>
</enterprise_catalog>

and in app/code/local/Mypackage/Mymodule/Model/Catalog/Product.php extend this class with Enterprise_Catalog_Model_Product_Url

Upvotes: 2

Antonino Bonumore
Antonino Bonumore

Reputation: 797

try to replace your

        <catalog>
            <rewrite>
                <product_url>Mypackage_Mymodule_Model_Catalog_Product_Url</product_url>
            </rewrite>
        </catalog>

with this

        <enterprise_catalog>
            <rewrite>
                <product_url>Mypackage_Mymodule_Model_Catalog_Product_Url</product_url>
            </rewrite>
        </enterprise_catalog>

Upvotes: 1

Related Questions