1

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 ..

Elavarasan
  • 2,579
  • 2
  • 25
  • 42

2 Answers2

2

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

Rehan Mobin
  • 558
  • 2
  • 14
  • Thanks Rehan. I knew if I extend Enterprise_Catalog_Model_Product_Url this class then I can able to rewrite Mage_Catalog_Model_Product_Url this class and it's functions. But my question is why I can't rewrite this class Mage_Catalog_Model_Product_Url ..? – Elavarasan Sep 13 '15 at 05:26
  • The problem with multiple rewrites is, only one node can be there due to the way Magento loads a modules XML, merges it with the config tree, and then loads another model. This means you can only ever have one class alias resolve to one class name. see this http://stackoverflow.com/a/7502938/2907851 – Rehan Mobin Sep 13 '15 at 09:22
1

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>
Antonino Bonumore
  • 787
  • 1
  • 13
  • 27
  • Thanks RehAntonino. I knew if I extend Enterprise_Catalog_Model_Product_Url this class then I can able to rewrite Mage_Catalog_Model_Product_Url this class and it's functions. But my question is why I can't rewrite this class Mage_Catalog_Model_Product_Url ..? – Elavarasan Sep 13 '15 at 05:26
  • Because in Enterprise this class has been alredy rewrited and in a priority higher than your, so your edit does not affect nothing. – Antonino Bonumore Sep 14 '15 at 15:38