November Happy Hour will be moved to Thursday December 5th.

Loading...

Recommended reading 

Index POCO objects instead of CatalogContentBase

This topic describes how to index POCO (Plain Old CLR Objects) objects instead of catalog content inheriting from CatalogContentBase. These examples apply to solutions with the EPiServer.Find.Commerce package installed.

Excluding CatalogContentBase from being indexed

To create a POCO class and index it in Find is easy, the problem is to figure out how the objects should be reindexed when content in the catalog has changed. We can make sure that nothing that inherits from CatalogContentBase gets indexed.

    public class SiteCatalogContentClientConventions : CatalogContentClientConventions
    {
        public override void ApplyConventions(IClientConventions clientConventions)
        {
            base.ApplyConventions(clientConventions);
            ContentIndexer.Instance.Conventions.ForInstancesOf<CatalogContentBase>().ShouldIndex(x => false);
        }
    }

Adding default price, prices, and inventory

Add properties to your POCO class that fits your needs. These are three examples: IEnumerable<Price> Prices, Price DefaultPrice, and IEnumerable<Inventories>. These properties can be populated by using ReadonlyPriceLoader and InventoryLoader.

Listening for updates

You can override methods that return a delegate for indexing content. We can create our POCO object, and index them.

    public class SiteCatalogKeyEventListener : CatalogContentEventListener
    {
        public SiteCatalogKeyEventListener(ReferenceConverter referenceConverter, IContentRepository contentRepository, IClient client, CatalogEventIndexer indexer, CatalogContentClientConventions clientConventions)
            : base(referenceConverter, contentRepository, client, indexer, clientConventions)
        {
        }

        protected override Action<IContent> GetIndexContentAction()
        {
            return (content) =>
            {
                // Create the POCO class here, and call the indexer
            };
        }

        protected override Action<IContent> GetIndexContentAndDescendantsAction()
        {
            return (content) =>
            {
                // Create the POCO class here, and call the indexer
            };
        }
    }
Do you find this information helpful? Please log in to provide feedback.

Last updated: Nov 03, 2015

Recommended reading