i need to change the layered navigation feature a little bit, currently it filter product attributes on "OR" condition like Product 1 Red, blue, pink

Product 2 Red

Product 3 Blue

On selecting filter options “red” and “blue” in the layered nav, the product collection includes Product 1, Product 2 and Product 3. I just want it to return Product 1. I tried to it by modifying

->where($alias.'.value IN (?)', $ids);


foreach ($ids as $key => $value) {
     $collection->getSelect()->where($alias.'.value = ?', $value);

but with this when i select two option, it doesn't return a value.

  • I don't think this will work. I assume you can only set one color for a product and if you make the select look like where color = red and color = green no product will match your query.
    – Marius
    Aug 31, 2015 at 7:02
  • Thanx @Marius for your reply. is it not possible to filter products that are available only in red and green? any workaround?
    – Haris
    Aug 31, 2015 at 7:14

1 Answer 1


In order to manage to get my task done. I overridden the applyMultipleValuesFilter($ids) to something like this

protected function applyMultipleValuesFilter($ids)
    $attribute  = $this->getAttributeModel();
    $table = Mage::getSingleton('core/resource')->getTableName('catalogindex/eav'); 
    $alias = 'attr_index_'.$attribute->getId();
    $hvngquery = ' ';
    $i= count($ids)-1;
    foreach ($ids as $key => $value) 
        $hvngquery .= '(SUM(`'.$alias.'`.`value`= "'.$value.'") > 0)';
        if ($i>0) 
          $hvngquery .= ' AND ';
         $i = $i-1;

    $collection = $this->getLayer()->getProductCollection();

        array($alias => $table),
    ->where($alias.'.store_id = ?', Mage::app()->getStore()->getId())
    ->where($alias.'.attribute_id = '. $attribute->getId()) 

    return $this;

This then generates an unknown field error in query (if you run the query directly in phpmyadmin it works but error occurs only in magento) for this i had to modify _getBaseCollectionSql() to add having clause to collection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.