Developer forum

Forum » Ecommerce - Standard features » FacetGroups Loop in Productlist template

FacetGroups Loop in Productlist template

Nicolai Normann
Reply

Hey,

Currently working on making a filter on a productlist using the new repository index.

I've made and built my index, made a query on it and attempted making a facetgroup.

Then I tried to insert the facetgroup loop in my productlist template, but the facetgroup isn't defined in my product catalog context, of where I expected it to be defined.

Then I tried to use the query publisher module to see if it was my productcatalog at fault. But the query publisher is also unable to list any facet groups.

I followed this guide http://doc.dynamicweb-cms.com/Default.aspx?ID=639 and have done everything the same way the guide suggests.

My application is currently running 8.7.2.2, but yesterday I tried to update my solution to 8.8.0.0 which didn't result in any difference (I've downgraded again since, I didn't have time to upgrade all our solutions on the project and the upgrade didn't fix my issue).

So my question is, shouldn't I be able to access the FacetGroup Loop in my Productlist template? Is the FacetGroup Loop undefined in my Productlist because it has no results?

I've attached an image with all my configurations.

Hope someone knows why, thanks in advance :)

facetgroup.png

Replies

 
Nicolai Høeg Pedersen
Reply

You configuration looks ok.

You write your "FacetGroup" loop - it is called "FacetGroups" - that might be it?

This code (Razor) should give you groups, their facets and their options.

@{

    foreach (LoopItem facetGroup in GetLoop("FacetGroups"))
    {
        foreach (LoopItem facetItem in facetGroup.GetLoop("Facets"))
        {
            int OptionWithResultCount = facetItem.GetInteger("Facet.OptionWithResultCount");
            var FacetName = facetItem.GetString("Facet.Name");
            int FacetOptionWithResultCount = facetItem.GetInteger("Facet.OptionWithResultCount");
            var FacetOptionCount = facetItem.GetInteger("Facet.OptionCount");
            var FacetOptionResultTotalCount = facetItem.GetInteger("Facet.OptionResultTotalCount");
            var FacetQueryParameter = facetItem.GetString("Facet.QueryParameter");
            <text>@FacetName<br></text>
            foreach(LoopItem FacetOption in facetItem.GetLoop("FacetOptions")){
                var FacetOptionValue = FacetOption.GetString("FacetOption.Value");
                var FacetOptionName = FacetOption.GetString("FacetOption.Name");
                var FacetOptionLabel = FacetOption.GetString("FacetOption.Label");
                bool FacetOptionSelected = FacetOption.GetBoolean("FacetOption.Selected");
                int OptionCount = FacetOption.GetInteger("FacetOption.Count");
                <text>@FacetOptionName (@OptionCount)<br></text>
            }
        }
    }
}

 
Nicolai Normann
Reply

That's merely a typo from my side, sorry about that.

When I write @TemplateTags() the loop isn't defined.

I've got this code in my productlist template:

@foreach (LoopItem facetGroup in GetLoop("FacetGroups"))
{
    foreach (LoopItem facet in facetGroup.GetLoop("Facets"))
    {

        <i>@facet.GetString("Facet.Name")</i>
        <select name="@facet.GetString("Facet.QueryParameter")">
            <option value="">@Translate("None", "None")</option>
            @foreach (LoopItem option in facet.GetLoop("FacetOptions"))
            {
                var value = option.GetValue("FacetOption.Value");
                var selected = option.GetBoolean("FacetOption.Selected");
                var label = option.GetString("FacetOption.Label");
                var count = option.GetInteger("FacetOption.Count");

                <option value="@value" selected="@selected">
                    @label (@count)
                </option>
            }
        </select>
    }
}

templatetags.png
 
Nicolai Høeg Pedersen
Reply

I need a URL to take a look.
 Do you get products in the list?

 
Mario Santos
Reply

Hi Nicolai,

I'm having the same issue at http://b2b.fasteddie.dw-demo.com/products/electronic-cases (Dw version: 8.8.0.0)

 

Best Regards,

Mário Santos

 
Nicolai Høeg Pedersen
Reply

Hi Mario

The problem with this one turned out to be a missing GroupID parameter and criteria in the search. Check out the dump.

BR Nicolai

Capture.PNG
 
Mario Santos
Reply

Hi Nicolai,

It's fine right now, thank you!

 

Best Regards,

Mário Santos

 

You must be logged in to post in the forum