简体   繁体   中英

Magento: Custom Product Collection Won't Populate Layered Navigation / Filters Broken

I'm building a custom 'Sale' page that will automatically show any product that has a sale price.

My approach has been to get the entire product collection and add filters for visible, has a sale price, has an image (needed for our store as we're integrated with a POS sytem so products are automatically created and visible from the POS).

My code for getting the products looks like this:

$_productCollection = Mage::getResourceModel('catalog/product_collection');
        $_productCollection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
        $_productCollection = $this->_addProductAttributesAndPrices($_productCollection)
         ->addStoreFilter() 
         ->addAttributeToSort('entity_id', 'desc') //THIS WILL SHOW THE LATEST PRODUCTS FIRST
        ->addAttributeToFilter('special_price', array('notnull' => 1)) // only products where special_price is not empty
        ->addAttributeToFilter('thumbnail', array('neq' => 'no_selection'))
         ->setPageSize($this->get_prod_count())
         ->setCurPage($this->get_cur_page());
        $this->setProductCollection($_productCollection);

$_helper = $this->helper('catalog/output');
$this->setData('column_count',5);

It works as expected and I get a list of products that are instock, on-sale, are visible and have an image. The only issue is that the layered navigation isn't populated any more. The category is most definitely set as 'Anchor' so that isn't the issue.

I believe this is because the layered navigation is looking for products assigned to the category and the category is empty - it's using a custom template which calls / overwrites with the above product collection.

So my question is if I am right with the above assumption, how can I send the results of the collection to the layered navigation?

I think you have to create a category and then add your collection results into it, so new category will contain products and will show layer navigation. Suggestion : Before trying anything new take a backup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM