I have created an observer that manipulates the advanced search result of Magento.
For this, I've used the controller_action_layout_render_before_catalogsearch_advanced_result
observer.
I'm using an "dummy" attribute called "brand". This attribute doesn't accually contain something, but is just there so that the user can input a value in the normal magento forms.
Now my problem is that I can not seem to remove this dummy attribute. I've tried removeAttributeFromFilter()
(and removeFieldFromFilter()
) but it does not seem to disappear.
I cannot just reset the WHERE statement, because all other attributes do need to function like normal.
The observer:
class Jeroen_SearchFilter_Model_Observers_Searchresults
{
function manipulateSQL( $event ){
if(!Mage::app()->getRequest()->getOriginalPathInfo() == "/catalogsearch/advanced/result/";){
//double check if this we're really using advanced search
return;
}
$block = Mage::app()->getLayout()->getBlock('search_result_list');
if($block){
$collection = $block->getLoadedProductCollection();
$searchFilterTable = Mage::getSingleton('core/resource')->getTableName('searchFilter/searchtable');
$collection->getSelect()->join(array("searchfilter" => $searchFilterTable), "e.entity_id = searchfilter.product_id" );
$collection->getSelect()->where("searchfilter.brandAttributeId = 'mybrand'");
$collection->removeAttributeFromFilter("brand");
$block->setLoadedProductCollection($collection);
}
}
}
Does anyone know how to remove the brand attribute from the collection?