0

In Magento 1.9 I would like to filter the products returned by the layered navigation. The collection should be filtered if the name contains a string passed through a parameter in the querystring, if present.

How can I achieve this results? Should I extend some layered navigation classes?

2

You cannot filter by names because Layer navigation only support attributes such as prices, drop-down or multi select.

1

You would have to write your own filter model that extends Mage_Catalog_Model_Layer_Filter_Abstract.

You can not use the core implementation for dropdown/multiselect attributes (Mage_Catalog_Model_Layer_Filter_Attribute) because it relies on the attribute index and exact matching.

To display the filter, you need to add a block that extends Mage_Catalog_Block_Layer_Filter_Abstract and rewrite Mage_Catalog_Block_Layer_View to include it.

0

This can be achieved by extending Mage_Catalog_Block_Product_List class.

This is my extended class

class Custom_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List{
    protected function _getProductCollection(){
        parent::_getProductCollection();
        $this->_productCollection->addAttributeToSelect(array('image', 'url_path'));
        // filter search string
        $q = Mage::app()->getRequest()->getParam('q');
        if($q){
            $this->_productCollection->addFieldToFilter('description', array('like' => '%' . $q . '%'));
        }

        return $this->_productCollection;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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