If you are using Optimizely Customized Commerce, the common wisdom is that you should be using serializable cart mode. It’s not perfect (we discussed the drawbacks in, um, my book), but generally it has performance benefits. But for any reason that you need to use the legacy cart mode, there is a switch you can use – IFeatureSwitch
which can be used to change between those modes
It is important to remember that IFeatureSwitch only switch between to modes, it does not migrate any carts between those two. there is a one time cart migration job but that’s it.
To change the cart mode, it is simply as this
GetInstance<IFeatureSwitch>().DisableFeature(SerializedCarts.FeatureSerializedCarts);
However, there is a catch here.
To let IOrderRepository
use the correct cart system, there is an ICartProvider
which will be either CartProvider
or SerializableCartProvider
. The problem is that happens much earlier in the pipeline than IInitializationModule
. In fact it is determined in IConfigurableModule.ConfigureContainer
, which means before any IInitializationModule.Initialize
. Even if we call DisableFeature
s in another ConfigureContainer
, there is no warranty that our code will be called before the framework code (the order of ConfigureContainer
execution is indeterministic )
But fortunately, we can do that inside Startup.Configure. Due to how the feature switch data structure, it’s not as simple as adding a setting in appsettings.json, but it can be done easily in code:
services.Configure<ApplicationOptions>(x =>
{
x.Features[SerializedCarts.FeatureSerializedCarts] = new ApplicationFeature
{
Feature = "SerializedCarts",
State = FeatureState.Disabled,
Type = "Mediachase.Commerce.Core.Features.SerializedCarts, Mediachase.Commerce"
};
});
Of course, this is a workaround. The feature switch should be done as documented. It will be fixed in the future.