Magento Questions Answered By Magento Experts

 

Sign in | Signup

16 Answers

How to use layered navigation with custom product lists?

Asked by: pavel.polyakov 4852 views ,
Questions

Hello Magento experts!

How I sould build by custom product list to make layered navigation work for it.

Now I get my products collection that way:

<span style="color: #007700">http://pavel.totalmagento.nl/magento_experts_1.phps</span>

and I’m updating layout with this code:
<span style="color: #007700"></span><span style="color: #007700"><span style="color: #007700">http://pavel.totalmagento.nl/magento_experts_2.phps<br /></span></span>

Layered navigation is shown for price field only. And it isn’t works (but I don’t expect it to work without changes in code).

So, could someone help me with the direction? How can I connect my custom product list with the layered navigation?

16 Answers



  1. +4 Votes Thumb up 4 Thumb down 0

    EcommerceDeveloper on Jun 10, 2010

    I’ve already done something looks like that.
    You should use collection from layer object. There is one trick that allows you to display all active product in your store, it’s setting is_anchor attribute to root category.
    So the code should look like the following:

    $layer = Mage::getSingleton(‘catalog/layer’);
    $layer->getCurrentCategory()->setIsAnchor(1);

    $productCollection = $layer->getProductCollection();
    $productCollection
    ->setPage(
    $this->getToolbarBlock()->getCurrentPage(),
    $this->getToolbarBlock()->getLimit()
    )
    ->addAttributeToFilter(‘news_from_date’,array(‘lt’ => now()))
    ->addAttributeToFilter(‘news_to_date’, array(‘gt’ => now()));

    reply


  2. -1 Votes Thumb up 0 Thumb down 1

    pavel.polyakov on Jun 11, 2010

    Thank you, EcommerceDeveloper.
    Now it’s clearer, but…

    With this code we can select products which belongs root category, but what to do to select products from the whole shop over layer?

    In my code new products from the whole shop are selected.
    Layered navigation has strong connection with the categories, but it works for the search somehow. Unfortunately I can’t understand how :)

    reply


  3. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jun 11, 2010

    This trick “$layer->getCurrentCategory()->setIsAnchor(1);” allows you select all products in current store :) So if product is visible in catalog, it will be visible in your list. Of course it should be assigned to some category in the store.

    reply


  4. 0 Votes Thumb up 0 Thumb down 0

    pavel.polyakov on Jun 11, 2010

    You are right, I can get exactly the same list of products.
    But again there is one but :(

    I found that when I’m updating layout of the page with this code (from CMS):

    After it the layer block shows, and I see only 1 product in my product list. That’s why I have thoughts about the category.

    How did you show your layer filter for your custom products list?

    reply


  5. 0 Votes Thumb up 0 Thumb down 0

    pavel.polyakov on Jun 11, 2010

    After another checking I can confirm – when xml layout update is placed I will see only that products which belongs directly to the default folder.

    So I see one solution for now – add all of products to the default category and to their own category. In that case it will work fine.

    reply


  6. +1 Votes Thumb up 1 Thumb down 0

    EcommerceDeveloper on Jun 11, 2010

    Pavel,

    You code was stripped in previous messages. I’ve found out that it’s this site problem. You should convert all html special chars to html entities.

    reply


  7. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jun 11, 2010

    What version of Magento do you use?

    reply


  8. 0 Votes Thumb up 0 Thumb down 0

    pavel.polyakov on Jun 11, 2010

    There is one more bug – I can’t edit my answers (probably because I’m the potic starter).

    Here is the missing code:
    <reference name="left">
    <block type="catalog/layer_view" name="catalog.leftnav" after="catalog.category-nav" template="catalog/layer/view.phtml"/>
    </reference>

    reply


  9. 0 Votes Thumb up 0 Thumb down 0

    pavel.polyakov on Jun 11, 2010

    I’m using 1.4.0.1

    reply


  10. +2 Votes Thumb up 2 Thumb down 0

    EcommerceDeveloper on Jun 11, 2010

    I cannot edit my answers either. So you’re not alone :)
    Actually to make it work right you should setIsAnchor to layer category before layer block rendering. So would be great if you extend the layer view block and use it in your layout update, so you might call it My_Module_Block_Layer_View and extend it from Mage_Catalog_Block_Layer_View. And in your implementation override _prepareLayout method where you should pass setIsAnchor(1) to layer category. I think it should resolve the problem.

    If you have any questions, don’t hesitate to ask :)

    reply


    • 0 Votes Thumb up 0 Thumb down 0

      Stacey Wright on Jun 19, 2010

      Hello,
      Is it possible to get more details about the files to be modified an the code to insert? I am a bit unclear on this, but think your solution is exaclty what I’ve been looking for. I am hoping to add layered navigation to my CMS page showing sale items.

      reply


      • 0 Votes Thumb up 0 Thumb down 0

        Magento Expert on Jun 21, 2010

        Hi Stacey,

        To add layer navigation to a CMS page showing sale items you don’t need to edit any file. Simply edit your CMS page in the admin – under the “Design” tab put this code:

        &lt;reference name="left"&gt;
        &lt;block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/&gt;
        &lt;/reference&gt;

        That will show the layered navigation at the very top of the left column on your CMS page. Of course make sure your CMS page layout is “2column with left bar”.

        While we’re at it – here’s the best way to show products in a CMS page:

        List products on a CMS page

        I hope this helps!



  11. 0 Votes Thumb up 0 Thumb down 0

    pavel.polyakov on Jun 11, 2010

    >> Actually to make it work right you should setIsAnchor to layer category before layer block rendering.

    This was the greatest advice :) Now it works.

    Thank you. You are better then all magentocommerce.com/forum :)

    reply


  12. 0 Votes Thumb up 0 Thumb down 0

    Magento Expert on Jun 21, 2010

    Here’s how to show layered navigation with custom product lists if you’re using a CMS page to list your products. No need to edit any file in that case.

    reply


    • 0 Votes Thumb up 0 Thumb down 0

      EcommerceDeveloper on Jun 29, 2010

      It’s one of the solutions only if you assign products directly to root store category. But it’s painful for client to mark product as “new” and then additionally add it to store root category.

      reply


      • 0 Votes Thumb up 0 Thumb down 0

        Magento Expert on Jun 29, 2010

        All you have to do is go to Catalog > Manage Categories and click on your root category. There click on the “Category Products” tab and select all the products you’d like to display. It’s quite easy.


Answer Question

Please use <code> </code> tags to display code.