What I'm trying to achieve is a little bit funky.
We have an attribute on certain items which is called Primary Item and set to true. What we're trying to achieve is the following:
1) On category page, with no filtering in layered navigation show only Primary Items. On layered navigation block, show counts of ALL items.
2) On category page with filtering of some sort, show all items that matches the filter property, regardless if its a primary item. On layered navigation block, show counts of ALL items.
3) On search, show all items that matches the search query, regardless if they are primary or not. On layered navigation block, show counts of ALL items.
We tried adjusting Catalog\Block\Product\List.php and added the following:
$this->_productCollection = $layer->getProductCollection();
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
if (isset($_filters) && !empty($_filters)){
//DO NOTHING
}elseif(empty($_filters)){
$this->_productCollection = $this->_productCollection->addAttributeToFilter('primary_item', array('eq' => 1));;
}
This indeed works in category listing but it also changes the layered navigation count values as we're changing the collection too early.
We also tried manipulating the actual block:
$_filters = Mage::getSingleton('Mage_Catalog_Block_Layer_State')->getActiveFilters();
if (isset($_filters) && !empty($_filters)){
//DO NOTHING
}elseif(empty($_filters)){
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id))
->addAttributeToFilter('primary_item', array('eq' => 1))
->load();
}
?>
Although it worked for 1+2, the search does not work at all and showing ALL primary items no matter what you search for. Moreover, the sorting in the category page stopped working (by price, by position, etc).