6

Can't seem to get it to show up.

This is how it's defined in layout files:

<block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/>

it's located here:

/app/design/frontend/name-space/default/template/catalog/layer/view.phtml

I'm attempting to add it to the CMS page via the Layout Update XML (Layout is 2 columns with left bar) section in the backend using:

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

I've also tried:

<reference name="content">
    <block type="enterprise_search/catalog_layer_view" name="catalog.content" before="-" template="catalog/layer/view.phtml">
</reference>

The former shows nothing at all and the latter shows a single category dropdown that redirects to that specific category page.

Also, the product collection on the CMS page is being loaded by a widget. Would this have some effect? In the CMS page Content section is found:

{{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"}}

The above widget calls a function called _getProductCollection() in order to generate the product Collection of new products:

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;
}
  • Can you give us more information about what you are trying to do? – Mayers Feb 3 '15 at 16:05
  • @MayersDev does that help? – easymoden00b Feb 3 '15 at 16:08
11
+50

Layered navigation needs an active category to be able to work. If I remember correctly this should do it.

<block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml">
   <action method="setCategoryId"><category_id>[category ID]</category_id></action>
</block>

As a side note, there is a free module that gives you pages with products and a layered navigation and some content fields like CMS pages.

https://github.com/magento-hackathon/layered-landing

-- EDIT

To have a category with new products create a custom module that runs a cron every night that assigns the products to the new category. Below will add all products added after last week.

[Namespace]_[Module]_Model_Cron 
{
    public function assignToNew()
    {
        $collection = Mage::getResourceModel('catalog/product_collection')
        $collection->addAttributeToFilter('updated_at', array('gteq' => date('Y-m-d', strtotime('-1 week')));
        $collection->addAttributeToFilter('status', 1);
        [...]
        // whatever you need to filter
        [...]

        $products = array_fill_keys($collection->getAllIds(), '1');

        $category = Mage::getModel('catalog/category')->load([id of the cat]);
        $category->setPostedProducts($products);

        $category->save();
    }
}
  • Okay, but i'm generating a collection based upon which products in our catalog are 'new'. What would I assign as the category_id in this case? – easymoden00b Feb 13 '15 at 15:07
  • and you want to be able to filter those based on attributes? – Sander Mangel Feb 13 '15 at 15:08
  • Yes. I'll attach the _getProductCollection function that is used in the widget as well. – easymoden00b Feb 13 '15 at 15:12
  • Ahh ok. I've done this before. The easiest way is to create a category, 'new', for example and run a cron every night that assigns the products to this category. Let me look if I can find the code – Sander Mangel Feb 13 '15 at 15:16
  • 1
    Hm I'm not sure it's even possible to load the filtered values on a cms page since it works with GET variables. You might be able to rewrite all the layered navigation links to post to this CMS page but that would be a major core hack – Sander Mangel Feb 13 '15 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.