Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Liam Dilley 152 posts 378 karma points
    Aug 22, 2018 @ 01:40
    Liam Dilley
    0

    Display product filters

    Hi All, I am looking to build a filter function for the collections for a store I have wedding dress store. The design has a filter at the top.

    • I can create the filter groups and have done within the backoffice.
    • I do not know how to fetch all the filter groups and then their filters to be able to display this. I just need the core bits to help me please.
    • I then just need to know how to do the constraints on apply to the current collection.

    Filter example

    I do not need much, once I have the right pointers I can handle the rest. It would be much appreciated - Thank You.

  • Liam Dilley 152 posts 378 karma points
    Sep 04, 2018 @ 00:20
    Liam Dilley
    100

    I had to work this out myself, little to know documentation and the notes on the intellisense are pretty vague.

    First you need to get the filters:

    var theFilterGroups = merchelloHelper.Filters.Product.GetAll()
    

    This will give you the filter groups that have been created. You can then loop through these.

    @foreach (var item in theFilterGroups){}
    

    To then get all the filter themselves for each group:

    var itemsFilters = item.Filters.ToList();
    

    And then you can loop through them:

    @foreach (var itemFilter in itemsFilters){}
    

    Example of a solution:

    @{
    var theFilterGroups = merchelloHelper.Filters.Product.GetAll(); 
    }
    
    @foreach (var item in theFilterGroups){
        <h5>@item.Name.ToString()</h5>
        @var itemsFilters = item.Filters.ToList();
        <div class="the-filters">
        @foreach (var itemFilter in itemsFilters){
            <span>@itemFilter.Name.ToString()</span>
        }
        </div>
    }
    
  • Andrew Wilson 11 posts 114 karma points
    Oct 10, 2018 @ 09:34
    Andrew Wilson
    0

    Hi Liam

    Just thought I'd add a note here regarding filtering products - I was having a similar problem and wrote a post here:

    https://our.umbraco.com/packages/collaboration/merchello/merchello/94099-filters#comment-297596

    Andrew

Please Sign in or register to post replies

Write your reply to:

Draft