Magento - CatalogSearch Module not working

I want to override the "prepareProductCollection" function of a layer in the base CatalogSearch module. Here is what I wrote:

File Path: Company/Module/Model/CatalogSearch/Layer.php

 class Company_Module_Model_CatalogSearch_Layer extends Mage_CatalogSearch_Model_Layer { public function prepareProductCollection($collection) { parent::prepareProductCollection($collection); Mage::getModel('cataloginventory/stock_item')->addCatalogInventoryToProductCollection($collection); $collection->getSelect()->order('is_in_stock desc'); return $this; } } 

And in the configuration file:

 <config> <modules> <Company_Module> <version>0.0.0.1</version> <Company_Module> </modules> <global> <models> <module> <class>Company_Module_Model</class> </module> <catalogsearch> <rewrite> <layer>Company_Module_Model_CatalogSearch_Layer</layer> </rewrite> </catalogsearch> </models> </global> </config> 

I think I can miss something? Can anyone help me with this?

+4
source share
3 answers

You missed the completion of the catalogsearch tag in config.xml

+1
source

add require_once (app / Mage / CatalogSearch / Model / Layer) at the top

0
source

I tried to do the same.
I followed several tutorials and tried several things. As a result, I had 503 errors all the time (without any maintanance.flag files - they worked well on other sites).
But I managed to fix it. I will show you what I have now, as well as what the reason is for 503 if someone encounters this problem:

I named the company Module / CatalogSearch and consists of three files:

app / code / local / Company / Catalog Search / Model / Layer.php:

 <?php class Company_CatalogSearch_Model_Layer extends Mage_CatalogSearch_Model_Layer { public function prepareProductCollection($collection) { parent::prepareProductCollection($collection); // YOUR CODE HERE return $this; } } 


app / code / local / Company / CatalogSearch / etc / config.xml:

 <?xml version="1.0"?> <config> <modules> <Company_CatalogSearch> <version>0.1</version> </Company_CatalogSearch> </modules> <global> <models> <catalogsearch> <rewrite> <layer>Company_CatalogSearch_Model_Layer</layer> </rewrite> </catalogsearch> </models> </global> </config> 


app / etc / modules / Company_CatalogSearch.xml:

 <?xml version="1.0"?> <config> <modules> <Company_CatalogSearch> <active>true</active> <codePool>local</codePool> </Company_CatalogSearch> </modules> </config> 


And it's all.

To problem 503: In the file app / code / local / Company / CatalogSearch / etc / config.xml I had

 <rewrite> <layer> Company_CatalogSearch_Model_Layer </layer> </rewrite> 

instead

 <rewrite> <layer>Company_CatalogSearch_Model_Layer</layer> </rewrite> 


Hope this helps!

0
source

All Articles