1
votes

I need to show only simple products in category page, but I cant set "not visible" to the configurable because I need the an active product page from the configurables.

I found this code to remove the configurables from the listing:

  $_productCollection=$this->getLoadedProductCollection();
  $_productCollection = clone $this->getLoadedProductCollection();
  $_productCollection->clear()
                     ->addAttributeToFilter('type_id', 'simple')
                     ->load();

  $_helper = $this->helper('catalog/output');

It works, but, In the layered navigation the configurable product are still counting. Its like "Color: Red (2)" but I just have 1 red (simple). How can I remove completly the configurable products?

1
Why are those products in the category to begin with if you don't want them there?clockworkgeek
Because when the user are in the product page (configurable), i need the full breadcrumb (Home > category > subcateogry > product) Im using a color swatch module. I want to display all simple products in the category page, and when the user clicks in some product, he goes to the configurable product of that simple product, with the full breadcrumbPaulo

1 Answers

2
votes

The layered navigation uses a collection object which is loaded separately.

One possible way to ensure correct counts next to the navigation filters is to override model Mage_Catalog_Model_Layer and add your filter to its function Mage_Catalog_Model_Layer::prepareProductCollection

public function prepareProductCollection($collection)
    {
        $collection
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addUrlRewrite($this->getCurrentCategory()->getId())
            ->addAttributeToFilter('type_id', 'simple');

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

        return $this;
    }

To achieve this create a module in your local code pool. In the config.xml file add the following node into the global node

<models>
        <catalog>
            <rewrite>
                <layer>YourPackage_YourModule_Model_Rewrite_Layer</layer>
            </rewrite>
        </catalog>
</models>

In your module add a directory 'Rewrite' under folder 'Model' and create a file Layer.php in it. In the created file Model/Rewrite/Layer.php add a class with the following definition:

class YourPackage_YourModule_Model_Rewrite_Layer extends Mage_Catalog_Model_Layer {
}

Add the function above into this class, clear cache.