Apply filter on collection Object
I am getting this object on list page
$_productCollection=$this->getLoadedProductCollection();
//return 3 records
now I applied filter as
$_productCollection=$_productCollection->addFieldToFilter('genre', array('finset' => '126'));
//now it should return 1 record
but it gives me a 开发者_开发技巧count of 3. Now, if I run the query in database by getting the query using echo $_productCollection->getSelect();
it returns 1 record.
Can anybody help me to resolve this?
Most likely this doesn't work because $this->getLoadedProductCollection()
returns a collection which already has been loaded by the catalog/layer
singleton.
But you could override Mage_Catalog_Model_Layer::prepareProductCollection()
to get in control and add the custom filters you want.
精彩评论