November Happy Hour will be moved to Thursday December 5th.

Cant disable SerializedCarts

Vote:
 

We're currently upgrading a solution from 13.31.1 to 14.15.6 and we're having some difficulties disabling the SerializedCarts feature wich is now enabled by default.

We've added the following initializable module that attempts to disable the SerializedCarts according to the documentation at https://docs.developers.optimizely.com/customized-commerce/docs/serializable-carts, we've also tried disabling the feature through appsettings.json.

    [InitializableModule, ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class CommerceInitializer : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            ServiceLocator.Current.GetInstance<IFeatureSwitch>().DisableFeature(SerializedCarts.FeatureSerializedCarts);
        }

        public void Preload(string[] parameters) {}
        public void Uninitialize(InitializationEngine context) {}
    }

The code executes successfully, but after e.g. adding a payment to the cart and calling _orderRepository.LoadOrCreateCart<ICart>(..) we get an exceptions with a stack trace that leads through SerializableCartDB, indicating that the feature is still enabled:

Exception details:

Value cannot be null. (Parameter 'target')

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null. Arg_ParamName_Name
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)
   at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
   at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader, Object target)
   at Mediachase.Commerce.Orders.PaymentConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at EPiServer.Commerce.Order.Internal.DataAccess.SerializableCartDB.CreateCarts(DataTable cartData) in EPiServer.Commerce.Order.Internal.DataAccess\SerializableCartDB.cs:line 327
   at EPiServer.Commerce.Order.Internal.DataAccess.SerializableCartDB.Load(CartFilter cartFilter) in EPiServer.Commerce.Order.Internal.DataAccess\SerializableCartDB.cs:line 105
   at EPiServer.Commerce.Order.Internal.SerializableCartProvider.Load(Guid customerId, String name) in EPiServer.Commerce.Order.Internal\SerializableCartProvider.cs:line 109
   at EPiServer.Commerce.Order.Internal.DefaultOrderRepository.<>c__DisplayClass12_0`1.<Load>b__0() in EPiServer.Commerce.Order.Internal\DefaultOrderRepository.cs:line 92
   at EPiServer.Commerce.Order.Internal.DefaultOrderRepository.ReadThrough[TOrderGroup](Guid customerId, String name, Type orderType, Func`1 load) in EPiServer.Commerce.Order.Internal\DefaultOrderRepository.cs:line 310
   at EPiServer.Commerce.Order.Internal.DefaultOrderRepository.Load[TOrderGroup](Guid customerId, String name) in EPiServer.Commerce.Order.Internal\DefaultOrderRepository.cs:line 102
   at EPiServer.Commerce.Order.IOrderRepositoryExtensions.LoadOrCreateCart[TCart](IOrderRepository orderRepository, Guid customerId, String orderTypeName, ICurrentMarket currentMarket) in EPiServer.Commerce.Order\IOrderRepositoryExtensions.cs:line 23
   at ...CartService.cs:line 158

  This exception was originally thrown at this call stack:
    Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(object, string)
    Newtonsoft.Json.JsonSerializer.PopulateInternal(Newtonsoft.Json.JsonReader, object)
    Newtonsoft.Json.JsonSerializer.Populate(Newtonsoft.Json.JsonReader, object)
    Mediachase.Commerce.Orders.PaymentConverter.ReadJson(Newtonsoft.Json.JsonReader, System.Type, object, Newtonsoft.Json.JsonSerializer)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(Newtonsoft.Json.JsonConverter, Newtonsoft.Json.JsonReader, System.Type, object)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(System.Collections.IList, Newtonsoft.Json.JsonReader, Newtonsoft.Json.Serialization.JsonArrayContract, Newtonsoft.Json.Serialization.JsonProperty, string)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(Newtonsoft.Json.JsonReader, System.Type, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonProperty, object, string)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(Newtonsoft.Json.JsonReader, System.Type, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty, object)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.JsonReader, System.Type)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(Newtonsoft.Json.JsonReader, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.ObjectConstructor<object>, string)
    ...
    [Call Stack Truncated]

During the call I checked the value of IFeatureSwitch.Features[0] and it seems to be disabled as it should be:

{Mediachase.Commerce.Core.Features.SerializedCarts}
    Name: "SerializedCarts"
    State: Disabled

Is my assumption correct that serialized carts are still being used? How can I disable the feature propperly? Or is SerializableCartDB supposed to be used even when the feature is disabled?

#315691
Edited, Jan 16, 2024 9:59
Vote:
 

The switch was checked at ConfigureContainer which was way before your code. It seems to be a bug for me - I will create one so it will be looked into. Meanwhile you can use the workaround here Switching away from serializable cart mode – Quan Mai's blog (vimvq1987.com)

#315693
Jan 16, 2024 12:25
Quan Mai - Jan 16, 2024 12:31
bug is COM-17649 (not yet public)
Vote:
 

Thanks! With the code you provided the feature was successfully disabled :)

#315698
Jan 16, 2024 12:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.