In this tutorial, you will learn how to write some code that will add a custom property to the cart class in Episerver Commerce. The code to add a custom property is very similar to adding a property to the Lineitem class (read this to learn how).

To add this metadata you will be using the OrderContext.Current. Specifically, when you work with the cart you will use OrderContext.Current.ShoppingCartMetaClass. To update the cart object you can use the CreateField method to add your custom property. The cart code to do this will look like this:

You can then access your property using the following code:

It is as simple as that 💥. The process for adding extra properties to the default Episerver Commerce objects are all very similar. You use OrderContext.Current, find the class that you want to modify, define a custom MetaField then use the AddField() method to store the property within the database. Happy Coding 🤘