0

I created a new model class called Company_CatalogSearch_Model_System_Config_ListSort which I used to create a copy of the Product Listing Sort By option from the catalog module, just for the catalogsearch module. My congif.xml looked like this:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_CatalogSearch>
            <version>0.0.1</version>
        </Company_CatalogSearch>
    </modules>
    <global>
        <blocks>
            <catalogsearch>
                <rewrite>
                    <result>Company_CatalogSearch_Block_Result</result>
                </rewrite>
            </catalogsearch>
        </blocks>
        <models>
            <catalogsearch>
                <class>Company_CatalogSearch_Model</class>
            </catalogsearch>
        </models>
    </global>
</config>

This was just fine as long as Magento was only trying to access Company_CatalogSearch_Model_System_Config_ListSort (my new model.) But as soon as it tried to use any other models, such as Mage_CatalogSearch_Model_Query I would get an error:

ERR (3): Warning: include(): Failed opening 'Company\CatalogSearch\Model\Query.php' for inclusion

I tried many, many different combinations of rewrites and more specific model definitions in the config.xml file but in the end the only way I could get this work was to either:

Option 1: Create a file with a blank class for each model which extended the Mage class, like so:

<?php
class Graybox_Catalogsearch_Model_Query extends Mage_Catalogsearch_Model_Query
{
    // This is just here because it has to be
}

Option 2: Create a rewrite for each and every one of the model classes for the catalogsearch module, like so:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_CatalogSearch>
            <version>0.0.1</version>
        </Company_CatalogSearch>
    </modules>
    <global>
        <blocks>
            <catalogsearch>
                <rewrite>
                    <result>Company_CatalogSearch_Block_Result</result>
                </rewrite>
            </catalogsearch>
        </blocks>
        <models>
            <catalogsearch>
                <class>Company_CatalogSearch_Model</class>
                <rewrite>
                    <advanced>Mage_CatalogSearch_Model_Advanced</advanced>
                    <fulltext>Mage_CatalogSearch_Model_Fulltext</fulltext>
                    <fulltext_observer>Mage_CatalogSearch_Model_Fulltext_Observer</fulltext_observer>
                    <indexer_fulltext>Mage_CatalogSearch_Model_Indexer_Fulltext</indexer_fulltext>
                    <layer>Mage_CatalogSearch_Model_Layer</layer>
                    <layer_filter_attribute>Mage_CatalogSearch_Model_Layer_Filter_Attribute</layer_filter_attribute>
                    <mysql4_advanced>Mage_CatalogSearch_Model_Mysql4_Advanced</mysql4_advanced>
                    <mysql4_advanced_collection>Mage_CatalogSearch_Model_Mysql4_Advanced_Collection</mysql4_advanced_collection>
                    <mysql4_fulltext>Mage_CatalogSearch_Model_Mysql4_Fulltext</mysql4_fulltext>
                    <mysql4_fulltext_collection>Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection</mysql4_fulltext_collection>
                    <mysql4_fulltext_engine>Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine</mysql4_fulltext_engine>
                    <mysql4_indexer_fulltext>Mage_CatalogSearch_Model_Mysql4_Indexer_Fulltext</mysql4_indexer_fulltext>
                    <mysql4_query_collection>Mage_CatalogSearch_Model_Mysql4_Query_Collection</mysql4_query_collection>
                    <mysql4_search_collection>Mage_CatalogSearch_Model_Mysql4_Search_Collection</mysql4_search_collection>
                    <mysql4_query>Mage_CatalogSearch_Model_Mysql4_Query</mysql4_query>
                    <resource_advanced>Mage_CatalogSearch_Model_Resource_Advanced</resource_advanced>
                    <resource_advanced_collection>Mage_CatalogSearch_Model_Resource_Advanced_Collection</resource_advanced_collection>
                    <resource_fulltext>Mage_CatalogSearch_Model_Resource_Fulltext</resource_fulltext>
                    <resource_fulltext_collection>Mage_CatalogSearch_Model_Resource_Fulltext_Collection</resource_fulltext_collection>
                    <resource_fulltext_engine>Mage_CatalogSearch_Model_Resource_Fulltext_Engine</resource_fulltext_engine>
                    <resource_helper_mysql4>Mage_CatalogSearch_Model_Resource_Helper_Mysql4</resource_helper_mysql4>
                    <resource_indexer_fulltext>Mage_CatalogSearch_Model_Resource_Indexer_Fulltext</resource_indexer_fulltext>
                    <resource_query_collection>Mage_CatalogSearch_Model_Resource_Query_Collection</resource_query_collection>
                    <resource_search_collection>Mage_CatalogSearch_Model_Resource_Search_Collection</resource_search_collection>
                    <resource_query>Mage_CatalogSearch_Model_Resource_Query</resource_query>
                    <system_config_backend_sitemap>Mage_CatalogSearch_Model_System_Config_Backend_Sitemap</system_config_backend_sitemap>
                    <query>Mage_CatalogSearch_Model_Query</query>
                    <session>Mage_CatalogSearch_Model_Session</session>
                </rewrite>
            </catalogsearch>
        </models>
    </global>
</config>

Obviously I'd rather not have to define each one of these, but I just can't get the other classes from the "parent" module to fallthrough correctly.

1

by adding this to your config.xml:

    <models>
        <catalogsearch>
            <class>Company_CatalogSearch_Model</class>
        </catalogsearch>
    </models>

You are telling Magento that each time you call Mage::getModel('catalogsearch/something_here') it will look for the model class in Company/CatalogSearch/Model/Something/Here.php.

And there are a lot of calls to Mage::getModel('catalogsearch/...').

Since you only added one model and you need that to be instantiated when you call

Mage::getModel('catalogsearch/system_config_listSort');  

You can do one of the following.
In both of them you need to remove the <models> tag from config.xml and replace with something else.

Option 1. - quick and dirty.

<models>
    <catalogsearch>
        <rewrite>
            <system_config_listSort>Company_CatalogSearch_Model_System_Config_ListSort</system_config_listSort>
        </rewrite>
    </catalogsearch>
</models>

Even if you are apparently rewriting an unexisting model it will still work.

Option 2 - clean

Change the prefix of your models.

 <models>
    <company_catalogsearch><!-- this instead of 'catalogsearh' -->
        <class>Company_CatalogSearch_Model</class>
    </company_catalogsearch>
</models>

Then, when you need an instance of your model just make it like this

Mage::getModel('company_catalogsearch/system_config_listSort');

Instead of

Mage::getModel('catalogsearch/system_config_listSort');
  • I swear I tried option 1, but I guess I got something about it wrong. I also tried option 2, but didn't realize I needed to update the getModel call. Very helpful, thank you! – Tyler V. Apr 9 '14 at 17:59
0

I think the problem is in these lines of your config.xml

   <models>
        <catalogsearch>
            <class>Company_CatalogSearch_Model</class>
        </catalogsearch>
    </models>

I think it should be

   <models>
        <catalogsearch>
            <class>Company_CatalogSearch_Model_System_Config_ListSort</class>
        </catalogsearch>
    </models>

Well, I think there should be something after the text Model otherwise you are telling Magento that you are rewriting the entire family of classes 'Company_CatalogSearch_Model_*' (as confirmed by your analysis above).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.