Magento layered navigation on custom product collection

Magento layered navigation on custom product collection

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento layered navigation on custom product collection

Magento Layered Navigation on Custom Product Collection

You’re developing a custom module for Magento (version 1.8.0.0) to display a list of related products for a specific product. You’ve successfully created your own module by overwriting the Mage_Catalog_Block_Product_List class, and you want to ensure that the layered navigation reflects only the custom product collection.

Understanding Your Method

Your _getProductCollection() method in the block file is correctly configured:

protected function _getProductCollection()
{
    // ... existing code ...

    $this->_productCollection = $prod->getRelatedProductCollection()
        ->addAttributeToSelect('required_options')
        ->addAttributeToFilter(array(array('attribute'=>'accessory_manufacturer','neq'=>false)))
        ->addAttributeToSort('position', 'asc')
        ->addStoreFilter()
        ->setPageSize(30)
        ->setCurPage(1);

    // ... remaining code ...

    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
    $this->setProductCollection($this->_productCollection);
}

You’re fetching the related products, filtering by a manufacturer attribute, sorting them by position, and applying store-specific filters. You’ve also added necessary product attributes and prices.

The Layered Navigation Challenge

The layered navigation is currently displaying all products instead of just those in your custom collection. This issue likely stems from Magento’s core functionality, which hard-codes the layered navigation to work with the default catalog product collection.

Potential Solutions

1. Override the Layer Class

You could override the Mage_Catalog_Model_Layer class and modify its behavior. However, this approach may lead to conflicts with other modules or future Magento updates.

2. Recreate the Layered Navigation

A cleaner solution is to create a new layered navigation that uses your custom product collection. Here’s how you can achieve it:

Step 1: Create a new block

Create a new block class, YourCompany_Catalog_Block_Product_List_YourCustomLayer, extending Mage_Catalog_Model_Layer.

class YourCompany_Catalog_Block_Product_List_YourCustomLayer extends Mage_Catalog_Model_Layer
{
    public function getAvailableFilterAttributes()
    {
        // Implement your custom filter attributes here
    }

    // Override other necessary methods like _initCategory(), _initProductList(), etc.
}

Step 2: Use the new block in your layout

Update your layout XML to use the new block.

<reference name="left">
    <block type="catalog/layer_view" name="yourcustomlayer" template="catalog/layer/view.phtml"/>
</reference>

Step 3: Pass the custom collection

In your controller or block, set the custom product collection to the productCollection variable before rendering the layered navigation.

$this->_productCollection = $prod->getRelatedProductCollection();
$this->setProductCollection($this->_productCollection);

The new layered navigation block will use this custom product collection by default.

Remember to update your template to use the correct block (catalog/layer/view.phtml should work).

Conclusion

Creating a custom layered navigation for your specific product collection requires careful handling of Magento’s core functionality. By creating a new layer block and setting the custom product collection, you can achieve the desired behavior without significantly altering Magento’s core files.

Ensure that all your customizations are well-documented and tested to avoid conflicts with future updates or other modules. For more detailed guidance on Magento development best practices, consider exploring resources from trusted providers like Laravel Company.

Happy coding!

Catalog Extensions Configuration Pricing

Our network