views:

65

answers:

3

Hi,

I’m trying to override Mage_Catalog_Model_Layer_Filter_Category. In system.log I’m getting a warning:

Warning: include(Mycomp_Catalog_Model_Layer_Filter_Category.php): failed to open stream: No such file or directory in /var/www/magento/includes/src/Varien_Autoload.php on line 93 Warning: include(): Failed opening ‘Mycomp_Catalog_Model_Layer_Filter_Category.php’ for inclusion (include_path=’/var/www/magento/includes/src:.:/usr/share/php:/usr/share/pear’) in /var/www/magento/includes/src/Varien_Autoload.php on line 93

What am I doing wrong?

Mycomp/Catalog/etc/config.xml:

<?xml version="1.0"?>
<config>
<modules>
    <Mycomp_Catalog>
        <version>0.1.0</version>
    </Mycomp_Catalog>
</modules>
<global>
    <models>
        <catalog>
            <rewrite>                    
                <layer_filter_category>Mycomp_Catalog_Model_Layer_Filter_Category</layer_filter_category>
            </rewrite>
        </catalog>
    </models>
</global>

Mycomp/Catalog/Model/Layer/Filter/Category.php:

class Mycomp_Catalog_Model_Layer_Filter_Category extends  Mage_Catalog_Model_Layer_Filter_Category
{

} 

app/etc/modules/Mycomp_All.xml:

<?xml version="1.0"?>
<config>
  <modules>
     <Mycomp_Catalog>
       <codePool>local</codePool>
       <active>true</active>
     </Mycomp_Catalog>
  </modules>
 </config> 
A: 

have you tried to require the file of the clas you're extending?
In Mycomp/Catalog/Model/Layer/Filter/Category.php add before class declaration:

require_once 'Mage/Catalog/Model/Layer/Filter/Category.php';

david parloir
That is generally only necessary for classes that cannot be autoloaded (e.g. controllers).
Joseph Mastey
+2  A: 

It doesn't appear here, so did you set up the models for the Mycomp_Catalog module? Amend your global section like this:

<global>
    <models>
        <catalog>
            <rewrite>                    
                <layer_filter_category>Mycomp_Catalog_Model_Layer_Filter_Category</layer_filter_category>
            </rewrite>
        </catalog>
        <mycompcatalog>
            <class>Mycomp_Catalog_Model</class>
        </mycompcatalog>
    </models>
</global>

That's my only guess off the bat. Hope that helps!

Thanks, Joe

Joseph Mastey
Editing to reflect that you're not going to want underscores in the groupname (mycomp_catalog), as that'll confuse Magento. Otherwise, spot on.
Alan Storm
Underscores in groupnames are fine, and aren't necessary for rewrites anyway
Greg
Yeah, scratch what I said about underscores, I jumped to the wrong conclusion with some test code.
Alan Storm
Why do I need the <mycompcatalog> part?I didn't see it in blog posts about overriding core models:http://inchoo.net/ecommerce/magento/how_to_override_magento_model_classes/ http://www.belanur.de/blog/2008/09/05/overriding-core-models-with-a-custom-module/
pablo
+1  A: 

These kinds of problems are notriously difficult to debug via a forum. Here's a module with a working override (at least, it works on my install of 1.4 CE) Diff it vs. yours to see what's different, or just try installing in on your install, and if it doesn't work you know there's a problem elsewhere.

http://alanstorm.com/testbed/Mycomp.tar.gz

Alan Storm
Thank you for the help. I tried your module and I'm getting the same error. When I remove the <layer_filter_category> part it works.
pablo
Your module works with a fresh install. I see that you commented the <mycompcatalog> part so it is not needed. I still don't understand why your module doesn't work on my previous installation. Thanks.
pablo
I thought that might be the case (which is why I posted the working module). You previous instalation either 1. Had a Custom Module installed which was interfering with things or 2. Had a core or lib file changed that was interfering with things. Using a diff tool to compare the two sources could help you isolate what that happened. The file that your autoload attempted to include (include(Mycomp_Catalog_Model_Layer_Filter_Category.php) indicated that your autoload code may have been altered (include(Mycomp/Catalog/Model/Layer/Filter/Category.php would be "normal")
Alan Storm