Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Serializable carts

Describes how to store cart data in a single table to load, update, and save cart information in Optimizely Commerce Connect.

In the SerializedCarts data model, all cart data is stored in one table, SerializableCart. This table contains these defined and searchable columns:

  • CartId
  • Created
  • Modified
  • Name
  • CustomerId
  • MarketId (Commerce Connect 11.0 and higher)
  • Data

The Data column is where all the cart data is serialized to JSON format and stored as a string.

Serializable components

All cart data is serialized to a JSON-formatted string before persisting it to the database. To achieve this, several cart components participate in the serialization/deserialization, which takes IMarket as a parameter.

Add custom data

Serializable components implement the IExtendedProperties interface. You can add custom values to the Properties collection on these components as long as the value can be JSON-serialized.

To convert a serialized cart with custom properties to a purchase order, the meta fields corresponding to the custom properties must be present on the purchase order type. See Extend order classes.

The mapping between the serialized cart's custom properties and the purchase order's corresponding meta fields is based strictly on the property name. A new serialized cart is created with an empty Properties collection, so it is not prepopulated with the keys or default values of the meta fields defined on the purchase order or the legacy cart metaclass.

Enable SerializedCarts

By default, the SerializedCarts mode is enabled on a new installation.

Use ApplicationOptions to enable or disable the SerializedCarts feature:

{
  "ApplicationOptions": {
    "Features": {
      "SerializedCarts": {
        "Feature": "SerializedCarts",
        "State": 0, // 0 = enabled, 1 = disabled
        "Type": "Mediachase.Commerce.Core.Features.SerializedCarts, Mediachase.Commerce"
      }
    }
  }
}

Alternatively, enable the SerializedCarts mode programmatically by adding the following code to an InitializeModule class:

ServiceLocator.Current.GetInstance<IFeatureSwitch>().EnableFeature(SerializedCarts.FeatureSerializedCarts);

Migrate existing legacy carts

If you switch from a legacy version to serializable carts, you may need to migrate existing carts. If so, run the LegacyCartsMigrationJob scheduled job (available in the CMS admin view) immediately after switching to complete the migration and remove legacy carts.

The migration job is not registered automatically. Follow these steps to install and run it:

  1. Delete any rows relating to LegacyCartsMigrationJob in the tblscheduleditem and tblPlugin tables.
  2. Install the EPiServer.Commerce.Migration.Legacy package.
  3. Run the job.
📘

Note

Run the scheduled job immediately after switching to serializable carts. After the legacy carts are migrated, the job is no longer visible in the CMS admin view.