By default, Magento will display the attributes of a bundled product in layered navigation, including the filterable attributes of the child products - whether they are optional bundle items or not. You can understand why they did this (think configurable products and their simple products attributes showing), but it's not always ideal.

We were recently asked to come up with a way to hide the child attributes of bundle products from the layered navigation on a store which is running Magento Enterprise 1.14.2, but the same logic applied to Community Edition 1.8+

First copy the following files to local app/code/local directory;


/app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php
/app/code/core/Mage/Bundle/Model/Resource/Bundle.php


First we'll edit the the file Mage_Bundle_Model_CatalogIndex_Data_Bundle. Find this function;


protected $_haveChildren = array(
                        Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_TIERS=>false,
                        Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES=>false,
                        Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_ATTRIBUTES=>true,
                        );


Amend the file like this;


protected $_haveChildren = array(
                        Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_TIERS=>false,
                        Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES=>false,
                        //Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_ATTRIBUTES=>true,
Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_ATTRIBUTES=>false,
                        );


This will stop the index's rebuilding the links between bundle items and their children.

Now open the file Mage_Bundle_Model_Resource_Bundle and find the following function;


public function saveProductRelations($parentId, $childIds)
    {
        
		Mage::getResourceSingleton('catalog/product_relation')
            ->processRelations($parentId, $childIds);
        
        return $this;
		
    }


This function tries to add to the catlaog_product_relation table when the bundle product is saved, which we dont want so amend it to look like this;


public function saveProductRelations($parentId, $childIds)
    {
        
		// PREVENT WRITING TO catalog_product_relation ON SAVE
		//Mage::getResourceSingleton('catalog/product_relation')
        //    ->processRelations($parentId, $childIds);
    
        //return $this;
		
		return true;
    }


The final step is to remove the bundle items already in the catalog_product_relation table. If you are NOT using configurable products in your store, you can go ahead and truncate the table. If you are using configurable products, you will need to generate a list of the bundle product ID's and delete them from the table. If for example your bundle product ID's were 100,101 and 102, you'd do this;


DELETE FROM catalog_product_relation WHERE parent_id in (100,101,102);


The final step now is to run a full reindex and flush your caches. Bundle product children will no longer appear in your layered navigation.