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.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Shell.ObjectEditing;

namespace Alloy11MVC.Business.Initialization
{
public class CustomOptinProcessServive : OptinProcessService
{
public CustomOptinProcessServive(IServiceClientFactory serviceClientFactory,
ICacheService cacheService, ICampaignSettings campaignSettings,
IAuthenticationService authenticationService)
: base(serviceClientFactory, cacheService, campaignSettings, authenticationService)
{
}

public override IEnumerable<SelectItem> GetAllowedOptInProcesses()
{
// GetAllOptInProcesses() returns a list of all opt-in processes where each item is a Tuple<long, string, string>:
// + Item1 is the Id of the optin process
// + Item2 is the Name of the optin process
// + Item3 is the Type of the optin process

var optinList = GetAllOptInProcesses().Select(x => new SelectItem() { Text = x.Item2, Value = x.Item1 });

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<IOptinProcessService, CustomOptinProcessServive>();
//context.Services.AddTransient<IOptinProcessService, CustomOptinProcessServive>();

//working
context.StructureMap().Configure(c => c.For(typeof(OptinProcessService)).Use(typeof(CustomOptinProcessServive)));
}

public void Initialize(InitializationEngine context)
{
}

public void Uninitialize(InitializationEngine context)
{
}
}
}