title: Magento layered navigation on custom product collection
body: <p>I have been working on a custom module for Magento (ver. 1.8.0.0) that shows a list of related products of a certain product.</p>
  
  <p>In order to achieve this I have created my own module by overwriting the <code>Mage_Catalog_Block_Product_List</code> class.</p>
  
  <p>Basically here's how it works:</p>
  
  <p>From a controller I catch the products <code>entity_id</code> and I store the product in the registry so I can use it inside my custom written Block which is called list.php</p>
  
  <p>Here is the method that fills the product collection:</p>
  
  <pre><code>protected function _getProductCollection()
  {
      if (is_null($this-&gt;_productCollection)) {
          $prod = Mage::registry('chosenproduct');
          $this-&gt;_productCollection = $prod-&gt;getRelatedProductCollection()
              -&gt;addAttributeToSelect('required_options')
              -&gt;addAttributeToFilter(array(array('attribute'=&gt;'accessory_manufacturer','neq'=&gt;false)))
              -&gt;addAttributeToSort('position', 'asc')
              -&gt;addStoreFilter()
              -&gt;setPageSize(30)
              -&gt;setCurPage(1);
          ;
  
          $this-&gt;_addProductAttributesAndPrices($this-&gt;_productCollection);
          Mage::getSingleton('catalog/product_visibility')-&gt;addVisibleInCatalogFilterToCollection($this-&gt;_productCollection);
          $this-&gt;setProductCollection($this-&gt;_productCollection);
      }
  
      return $this-&gt;_productCollection;
  }
  </code></pre>
  
  <p>I also added the following in the layout .xml of my custom module to make sure the layered navigation shows:</p>
  
  <pre><code>&lt;reference name="left"&gt;
          &lt;block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/&gt;
      &lt;/reference&gt;
  </code></pre>
  
  <p>The layered navigation shows, but it seems that it is taking all products as collection instead of the custom collection that is used in the method I added above.</p>
  
  <p>I also know that I can get the catalog/layer using this <code>$layer = Mage::getSingleton('catalog/layer');</code></p>
  
  <p>The layer class also has a method called prepareProductCollection and setCollection but for some reason I can't get it to work.</p>
  
  <p>Any help on this?</p>
  
  <p>Basically I want to have the layered navigation for the products that are in the custom collection.</p>
  
  <p>Thanks,</p>