Connect for Campaign Add-on: Cannot retrieve Opt-in processes with the type other than "Double"

  • Updated

There is an issue with the Campaign Connector which only allows Opt-in processes of the type "Double" to be selected. We haven't got a fix for this but there's a workaround. By adding the following code, the Connector will get all opt-in processes (of all types) and a custom "No opt-in" process as an alternative selection.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.ConnectForCampaign.Core.Configuration;
using EPiServer.ConnectForCampaign.Core.Implementation;
using EPiServer.ConnectForCampaign.Services;
using EPiServer.ConnectForCampaign.Services.Implementation;
using EPiServer.ConnectForCampaign.Services.Implementation.Internal;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Shell.ObjectEditing;


namespace AlloyCMS12.Business.Initialization
{
    public class CustomOptinProcessServive : OptinProcessService
    {

        public CustomOptinProcessServive(ICacheService cacheService, 
            ICampaignSettings campaignSettings,
            IRESTService rESTService,
            IAuthenticationService authenticationService) : base(cacheService, campaignSettings, rESTService, authenticationService)
        {
        }

        public override IEnumerable<SelectItem> GetAllowedOptInProcesses()
        {
            var optinList = GetAllOptinProcess().Elements.Select(x => new SelectItem() { Text = x.Name, Value = x.Id });

            var noOptinList = new SelectItem[] { new SelectItem() { Text = "No opt-in", Value = 0 } };
            return optinList.Concat(noOptinList);
        }
    }

    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.ConnectForCampaign.Implementation.InitializationModule))]
    public class CustomCampaignConnectorInitialization : IConfigurableModule
    {
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.AddSingleton<OptinProcessService, CustomOptinProcessServive>();

        }

        public void Initialize(InitializationEngine context)
        {
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }
}