Magento CMS – Fixing Layered Navigation Not Populated by Collection Attributes

attributescmscollection;layered-navigation

I'm attempting to add layered navigation to a CMS page containing a widget that contains a custom product collection (products that are 'new'). Within this widget are fuctions that, given the correct parameters, will filter this collection. How do I pass this collection to the layered navigation block and have it's attributes show up?

This is how I am calling the layered navigation in the CMS custom layout XML:

<reference name="content">
        <!-- Layered Navigation Block -->
        <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml" >
        </block>
</reference>

This is how i'm calling the product collection onto the CMS page:

{{widget type="catalog/product_widget_new" display_type="new_products" show_pager="1" products_count="60" template="catalog/product/widget/new/content/new_grid.phtml"}}

This is how i'm generating the product collection in the widgets block:

protected function _getProductCollection()
{
    $todayStartOfDayDate = Mage::app()->getLocale()->date()
        ->setTime('00:00:00')
        ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    $todayEndOfDayDate = Mage::app()->getLocale()->date()
        ->setTime('23:59:59')
        ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
    $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToFilter('news_from_date', array('or' => array(
            0 => array('date' => true, 'to' => $todayEndOfDayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToFilter('news_to_date', array('or' => array(
            0 => array('date' => true, 'from' => $todayStartOfDayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToFilter(
            array(
                array('attribute' => 'news_from_date', 'is' => new Zend_Db_Expr('not null')),
                array('attribute' => 'news_to_date', 'is' => new Zend_Db_Expr('not null'))
            )
        )
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1);
    return $collection;
}

The widget's template page is a standard practice way to display price, reviews, pictures, etc in a pagesize varient format.

Best Answer

Layered navigation needs an active category to work. Add the following block to you layout-xml on your cms-pages.

<cms_page>
    <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml">
        <action method="setCategoryId"><category_id>2</category_id></action>
    </block>
</cms_page>