Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Quan Mai
Oct 16, 2018
  2205
(7 votes)

Extending Commerce campaign facets

It's fair to say Commerce sites are imcomplete without sales campaigns and promotions. Episerver Commerce fully supports that and even better, it allows you to handle (fairly *) big number of campaigns and promotions with ease. One of the most highly anticipated features that was added to Commerce last year was the Campaign facet groups, which allows you to filter campaigns and promotions without breaking a sweat:

This is great because it allows you to quickly navigate/filter by campaign statuses, promotion types and markets. However, can it be even greater?

What if you have one type of promotion so you don't bother showing other types? Or if you have 4 markets, and everytime you want to filter by the forth market, you would have to click on the expand button on the market filter, so you can select it. Or if you have more filters, based on the targeting visitor groups of the campaigns?

Until now, it is possible, but with a ceveat. You have to do things that you should not have to (and probably don't want to) to get it done.

Worry no more, with the upcoming Commerce 12.10, it is, hopefully, much easier.

Commerce 12.10 introduces FacetGroupModifier, which can be overriden to change the builtin facet groups, or to add new facet groups. Let's go back to previous example: let's make the market facet group show 4 markets all the time:

 public class CustomFacetGroupModifier : FacetGroupModifier
    {
        public override IEnumerable<FacetGroup> ModifyFacetGroups(IEnumerable<FacetGroup> facetGroups)
        {
            var marketFacetGroup = facetGroups.FirstOrDefault(f => f.Id == CampaignFacetConstants.MarketGroupId);
            if (marketFacetGroup != null)
            {
                marketFacetGroup.Settings.ItemsToShow = 4;
            }
            return facetGroups;
        }
    }


 So FacetGroupModifier has only one method that take a list of FacetGroup and returns one. Here you can decide what to do with the builtin facet groups (which is passed to you), by changing their settings, remove one or more, or decide to add your own. And then you just need to register your implementation in one of your IConfigurableModule

 public void ConfigureContainer(ServiceConfigurationContext context)
        {
            var services = context.Services;
services.AddSingleton<FacetGroupModifier, CustomFacetGroupModifier>();
        }

And that's it, my friends :)

Commerce 12.10 is being baked (read, being tested by our QAs) and will be released in one week or so.

*: By Fairly, I meant thousands. Anything more than a dozen thousands is on the edge of the UI.

Oct 16, 2018

Comments

Jafet Valdez
Jafet Valdez Oct 16, 2018 02:50 PM

Very nice! Looking forward to testing this out. laughing

Jeroen Stemerdink
Jeroen Stemerdink Oct 17, 2018 11:33 AM

Cool! So that would mean that when filter my campaigns for acces, like I wrote about here, I can make the count in the facets reflect the actual filtered value?

Quan Mai
Quan Mai Oct 18, 2018 08:22 AM

Without digging into your blog post - I would probably say yes. Here you can control what you would like to show and if you set the FacetItem.Count to correct value then it should work :) 

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog