This topic describes the SerializedCarts model in Episerver Commerce. With this model, all cart data is stored in a single table, providing a fast and efficient way to load, update, and save cart information.
In this topic
In the SerializedCarts data model, all cart data is stored in one table, SerializableCart. This table contains these defined and searchable columns:
MarketId (Commerce 11.0 and up only)
The table's last column is the Data column, where all the cart data is serialized to JSON format then stored as a string.
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 procedure. The following components are used:
Consequently, a custom JSON converter (which inherits from JsonConverter) is needed for each new component.
Important! The JSON converter is not supported in Commerce versions 11.0 and up.
Note: All components and custom JSON converters are internal, which means that the classes support the Episerver infrastructure, and are not intended to be used directly from your code.
This serializable cart system eliminates any relations to MetaDataPlus (MetaObject) (used in legacy versions). Therefore, when creating cart components (such as order form, shipment, line item, and so on), the system needs a factory that is different from the one used for purchase orders and payment plans.
The legacy system uses IOrderFactory for all carts (ICart), purchase orders (IPurchaseOrder) and payment plans (IPaymentPlan).
The IOrderFactory interface is now obsoleted. The SerializedCarts data model introduces new ways to create components that work in both legacy systems and new system:
IOrderGroupFactory. Responsible for creating instances of order group components by using IOrderGroupBuilder. The default implementation automatically registers all builders for all types of IOrderGroup.
Extension methods for IOrderGroup were also added for creating components by using IOrderGroupFactory. The following example shows usage.
cart.AddLineItem(OrderFactory.CreateLineItem(code), OrderFactory); // old way cart.AddLineItem(cart.CreateLineItem(code, OrderGroupFactory), OrderGroupFactory) // new way
See the latest Episerver Commerce QuickSilver sample site for an example of using IOrderGroupFactory.
In legacy versions, inventory information was wrapped in the concrete classes LineItem and Shipment. Since that information is needed for new carts, these now exist in separate interfaces:
To work with the new mode, you need to migrate all custom implementations of IShippingGateway and IPaymentGateway / ISplitPaymentGateway to IShippingPlugin and IPaymentPlugin / ISplitPaymentPlugin. The new interfaces use IShipment instead of Shipment and IPayment instead of Payment.
Note: The implementation of IShippingGateway and IShippingPlugin requires a constructor which takes IMarket as a parameter.
Serializable components implement the IExtendedProperties interface, and custom values can be added to the Properties collection on the Serializable components as long as the value can be JSON serialized.
Note 1: Converting a serialized cart with custom properties to a purchase order requires the Meta Fields corresponding to the custom properties to be present on the purchase order type. See Extending order classes.
Note 2: The mapping between the serialized cart's custom properties and the purchase order's corresponding meta fields is strictly based on property name. The serialized cart is created with an emptyProperties collection, that is, it is not prepopulated with the keys or default values of the meta fields added to the purchase order or the legacy cart meta class.
By default, the SerializedCarts mode is enabled for a new installation site and disabled for an upgraded site.
To enable SerializedCarts mode, do the following:
If that setting does not exist, add it like this:
<add feature="SerializedCarts" state="Enabled" type="Mediachase.Commerce.Core.Features.SerializedCarts, Mediachase.Commerce" />
Alternatively, enable the SerializedCarts mode programmatically by adding the following to your InitializeModule class:
If switching from a legacy version to Serializable carts, you may need to migrate existing carts. If so, run the scheduled job LegacyCartsMigrationJob (available in the CMS admin view) immediately after switching to the new cart system to complete the migration and remove legacy carts.
Note: You should run the scheduled job immediately after switching to serializable carts. After migrating legacy carts, the job is no longer visible in CMS admin view.
Last updated: Aug 18, 2017