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.