John K
John K

Reputation: 28869

Workaround for removed AutomaticContactMerger class in Kentico 10

We've upgraded a Kentico 8.2 website that uses the AutomaticContactMerger class, up to Kentico 10 which no longer contains that class. The API Changes reference guide notes the class as being removed in Kentico 10 but does not suggest alternatives or workarounds to using its merging features.

TL;DR Summary

We are looking for a way to port our Contact Management custom merge logic and integrate it into Kentico 10 at the point Kentico runs its default merge logic, just as we did in Kentico 8 as shown in this post (below).

Before hacking into the Kentico 10 API -- whatever that might look like -- I'm looking for recommendations or workarounds to best use the Kentico 10 APIs to achieve the same outcomes: to register custom mergers that will participate in the Kentico 10 default merge process.

Customization of Merge Logic

Specifically, our project overrides the Kentico 8 AutomaticContactMerger class and provides custom logic as shown in the following C#.NET Kentico 8 code snippet. (This code has been simplified and sanitised to convey the basic scenario.)

To understand this code:

/* In Kentico 8 we derive from the CMS.OnlineMarketing.AutomaticContactMerger class 
to provide custom merge logic
based on custom contact fields and rules ... */

public class CUSTOM_ContactMerger : AutomaticContactMerger /* K10 Removed ACM class */ { 

  // ==============================================
  // In K8 OVERRIDE the default Merge with our custom logic. 

  protected override ContactInfo MergeWithinSite(ContactInfo contact, List<ContactInfo> contacts, string siteName) {
    
    if (!base.ContactIsMergedByColumn(FieldNames.Contact.EXTERNAL_REFERENCE_VALUE)) {

      /* Custom logic determines which contacts will be merged */
      var contacts = CUSTOM_GetAllTheContactsIWantToMergeBasedOnCustomRules(..);

      /* Find or make a master contact - more custom rules wrapped up */
      ContactInfo masterContact = CUSTOM_GetMyPreferredMasterContactOrMakeANewOne();

      /* Use Kentico's ContactHelper class to merge all our picked Contacts into the master contact.*/
      ContactHelper.Merge(masterContact, contacts, null, null); // however the .Merge methods are gone in K10 

      return masterContact; // custom selection


  // ==============================================
  // in K8 OVERRIDE the Where Condition for when merge should be ignored (for example).

  protected override string GetWhereCondition(ContactInfo contact) {
    if (CUSTOM_ShouldIgnoreMerge(contact)) {
      return string.Empty;
    }
    return base.GetWhereCondition(contact) ?? string.Empty;
  }

A short list of classes and methods we use in the above Kentico 8 code snippet to provide custom merge behaviour, and which no longer exist in the Kentico 10 API are these:

CMS.OnlineMarketing namespace -

Registering Custom Merge Logic with Kentico 8

Additionally, we register our own CustomContactMerger class with Kentico 8 through a provider in the following standard way. The Kentico 8 method CMS.OnlineMarketing.ContactInfoProvider.AddAutomaticContactMerger(..) also no longer exists in Kentico 10, so we will need a way to register custom mergers in Kentico 10. Kentico 8 describes this method as /// Registers automatic contact merger that gets ran when method SetContactInfo is called.

[assembly: RegisterCustomProvider(typeof(CustomContactInfoProvider))]
public partial class CustomContactInfoProvider : ContactInfoProvider

    static CustomContactInfoProvider()
    {
        var myCustomMerger = new CustomContactMerger(..);

        // Note: we do NOT use Kentico's own email settings, because they will be picked up
        // by Kentico's private method and give email higher priority (than our own merger logic)

        var emailMerger = new CustomContactMerger("ContactEmail", CustomContactMerger.SETTING_MERGE_BY_EMAIL);

        var mergers = new List<CustomContactMerger>()  { merger, emailMerger };
        foreach (var m in mergers)
        {
            // Kentico 8 registration point. Kentico 10 does not have this method call.
            base.AddAutomaticContactMerger(m);
        }

Other Reference Information

Kentico 10 Release Notes about changes to contact management in the core product, as it relates to CMS Desk features:

By default, the system only merges contacts automatically, which caused the following changes:

  • It is no longer possible to merge accounts and split the merged accounts in the Contact management application.
  • It is no longer possible to manually merge contacts and split the merged contacts in the Contact management application.
  • It is no longer possible to clone the merged accounts in the Clone account dialog and the merged contacts in the Clone contact dialog.
  • The Automatic merging of contacts setting category with the following settings was removed from Settings -> On-line marketing -> Contact management -> Global data & merging:
    • Merge contacts for identical E-commerce customers; Merge contacts for identical Email campaign subscribers; Merge contacts with identical email addresses and When a visitor has more contacts, use.

~ https://docs.kentico.com/k10/release-notes-kentico-10#Releasenotes-Kentico10-Contactmanagement

Upvotes: 0

Views: 139

Answers (1)

Mcbeev
Mcbeev

Reputation: 1529

There was a major change to contacts in version 10 of Kentico. I would refer to the release notes here: https://docs.kentico.com/k10/release-notes-kentico-10#Releasenotes-Kentico10-Contactmanagement

Check out the paragraph that starts with

By default, the system only merges contacts automatically, ...

As far as recommendations go, I would try a test site with no customization at all to understand how contacts and activities work, the new out of the box setup may just work for you.

Alternately, if you share your merge logic we might be able to help more.

Upvotes: 0

Related Questions