Try our conversational search powered by Generative AI!

Viet Anh
Oct 1, 2018
  2743
(3 votes)

Customizing catalog export contents to Episerver Campaign

My first blog post on EPiServer World :)

At the end of Sept 2018, we introduced new package named EPiServer.Campaign.Commerce, that supports exporting catalog content to EPiServer Campaign.

The developer guide document for this new feature can be found here. This blog focuses on how to customize the data to be exported.

  • IProductLoader
    • GetEntries: Gets the entries need to export to campaign. By default, this collects all variants and packages under selected catalog and market language.
      Note: Since the catalog data is exported to Campaign system for marketing purpose. Then the core service only use items with price. The ones without price won't be processed.

      For example, you want to export variant under catalog, but not packages. Then your customization can be something like this:

          [ServiceConfiguration(ServiceType = typeof(IProductLoader), Lifecycle = ServiceInstanceScope.Singleton)]
          public class CustomProductLoader : IProductLoader
          {
              private readonly IContentLoader _contentLoader;
              private readonly ReferenceConverter _referenceConverter;
      
              public CustomProductLoader(IContentLoader contentLoader, ReferenceConverter referenceConverter)
              {
                  _contentLoader = contentLoader;
                  _referenceConverter = referenceConverter;
              }
      
              public IEnumerable<EntryContentBase> GetEntries(IEnumerable<string> catalogNames, IMarket market)
              {
                  var catalogs = catalogNames.Any()
                      ? _contentLoader.GetChildren<CatalogContent>(_referenceConverter.GetRootLink()).Where(x => catalogNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))
                      : _contentLoader.GetChildren<CatalogContent>(_referenceConverter.GetRootLink());
      
                  foreach (var catalog in catalogs)
                  {
                      foreach (var variant in _contentLoader.GetChildren<VariationContent>(catalog.ContentLink, market.DefaultLanguage))
                      {
                          yield return variant;
                      }
                  }
              }
          }


  • IProductFieldsHandler
    • PopulateCategoryFields: Gets the category hierarchy of a product. The category levels are separated by "#". Note that Campaign system can process up to 10 levels of category.
    • PopulateTextFields: Populates the fields Text1-Text10
      For example:

              public void PopulateTextFields(ProductModel model, EntryContentBase entry, IPriceValue price, IEnumerable<DiscountPrice> discountedPrices)
              {
                  var fashion = entry as FashionVariant;
                  model.Text1 = fashion.Size;
                  model.Text2 = fashion.Color;
                  model.Text3 = fashion.MinQuantity.ToString();
                  model.Text4 = fashion.MaxQuantity.ToString();
                  model.Text5 = fashion.Weight.ToString();
                  model.Text6 = discountedPrices?.FirstOrDefault()?.Price.ToString() ?? string.Empty;
                  model.Text7 = price.UnitPrice.ToString();
              }


    • PopulateImageFields: Populates the fields Image1-Image6
      For example:

              public void PopulateImageFields(ProductModel model, EntryContentBase entry)
              {
                  model.Image1 = new ProductImageModel
                  {
                      ImageUrl = "http://LinkToImage1.com",
                      ImageLink = "http://Image1HrefLink.com"
                  };
      
                  model.Image2 = new ProductImageModel
                  {
                      ImageUrl = "http://LinkToImage2.com",
                      ImageLink = "http://Image2HrefLink.com"
                  };
      
                  model.Image3 = new ProductImageModel
                  {
                      ImageUrl = "http://LinkToImage3.com",
                      ImageLink = "http://Image3HrefLink.com"
                  };
              }



    • PopulateLinkFields: Populates the fields Link1-Link3
      For example:

              public void PopulateLinkFields(ProductModel model, EntryContentBase entry)
              {
                  model.Link1 = new ProductLinkModel()
                  {
                      Text = "Link 1",
                      Url = "http://LinkToProduct1.com"
                  };
      
                  model.Link2 = new ProductLinkModel()
                  {
                      Text = "Link 2",
                      Url = "http://LinkToProduct2.com"
                  };
      
                  model.Link3 = new ProductLinkModel()
                  {
                      Text = "Link 3",
                      Url = "http://LinkToProduct3.com"
                  };
              }


    • PopulateAdditionalDataFields: Populates the fields AdditionalData1-AdditionalData20

In default implementation, EPiServer set default value for texts, images, links, additional data and category in corresponding methods. Then if you only override some of those methods, be sure to override correct data in correct method. For example, overriding for PopulateTextFields should only set model.Text[x]. Otherwise, your custom value may be reset somewhere else by the default implementations.

Hope this helps.

Oct 01, 2018

Comments

Please login to comment.
Latest blogs
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

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024