Try our conversational search powered by Generative AI!

Filter catalog content on market in content area

Vote:
 

Hi,


Is there a way to filter content area items, in this case products (EntryContentBase which has implementation of markets), so that we're only render items that are in the current market? I guess this question goes for other content types and custom filtering as well.


From what I know there is no convenient way to bind your own content area items to a PropertyContentAreaControl.


And when we're at it, there should be an implementation of IContentFilter that filters content on the current market. Right now we have to do it by calling the extension method IsAvailableInCurrentMarket() on every content item, which works but doesn't follow the same convention as in CMS.

#85252
Apr 19, 2014 1:30
Vote:
 

Hi,

I think you should create an custom control for contentarea and inject your custom content filter:

[TemplateDescriptor(TagString = "FilterByMarket")]
    public class MyContentAreaControl : PropertyContentAreaControl, IRenderTemplate<ContentArea>
    {
        private ContentControlResolver _contentControlResolver;
        new public ContentControlResolver ContentControlResolver
        {
            get
            {
                var contentControlResolver = _contentControlResolver ?? (_contentControlResolver = ServiceLocator.Current.GetInstance<ContentControlResolver>());
                if (contentControlResolver.ContentFilter == null)
                {
                    contentControlResolver.ContentFilter = new FilterContentForMarket();
                }

                return contentControlResolver;
            }
            set
            {
                _contentControlResolver = value;
            }
        }
    }

    public class FilterContentForMarket : IContentFilter
    {
        public bool ShouldFilter(IContent content)
        {
            //TODO: Get current market and check whethers the current content is in current market or not.
        }
    }

    

Some helpful links you may need:

  1. EPiServer 7 – Rendering of content (Johan Björnfot)
  2. Custom renderers for properties (Linus Ekström)
  3. Custom rendering of content areas (Joel Abrahamsson)

// Ha Bui

#85257
Edited, Apr 21, 2014 9:34
Vote:
 

That's a nice solution. Thank you.

#85386
Apr 24, 2014 9:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.