Using below code i'm getting list of filterable attributes

$layer = Mage::getModel("catalog/layer");
$attributes = $layer->getFilterableAttributes();

I can't able to set filters and get it's sub filters. example i have below 2 filterable attributes,

 28 (1)
 30 (2)

 Green (2)
 Red (1)

On selecting Size 28, my sub filter is

 Red (1)

So i'm trying to achieve below,

  • Get all available attribute filters initially (got this using getFilterableAttributes())

  • Set filter programatically and get it's sub filters as like above example

1 Answer 1


To set some "initial" filters you can rewrite the app\code\core\Mage\Catalog\Model\Layer.php class and adjust the product collection in the method getProductCollection:

    $collection = parent::getProductCollection();
    $db = Mage::getSingleton('core/resource')->getConnection('core_read');
    $tableAlias = 'amasty_example';
    $conditions = array(
        "{$tableAlias}.entity_id = e.entity_id",
        $db->quoteInto("{$tableAlias}.attribute_id = ?", 198),
        $db->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()),
        $db->quoteInto("{$tableAlias}.value = ?", 67)

        array($tableAlias => Mage::getSingleton('core/resource')->getTableName('catalog/product_index_eav')),
        implode(' AND ', $conditions),

the code above is based on app\code\core\Mage\Catalog\Model\Resource\Layer\Filter\Attribute.php

  • I have tried your solution but it doesn't work well. Because the navigation filters remains unfiltered as well as the toolbar appear with the incorrect products count. Whereas if I put the attribute filter in function prepareProductCollection() [model/Layer.php] it works fine. Can you elobarote your example a bit more. Jul 21, 2016 at 8:51

Your Answer

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

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