Extend order classes
Describes how to extend order classes in Optimizely Commerce Connect.
The order system default implementation contains many classes that you can extend with your own fields. Customize fields to add to all order objects to support your business use cases.
Classes in this topic are available in the Mediachase.Commerce.Orders namespace. You can extend the following order classes:
CartPurchaseOrderPaymentPlanOrderFormPaymentShipmentLineItemOrderGroupAddressType
Work with metadata types
The default implementation uses Mediachase.MetaDataPlus for its storage of extended attributes. The list of available types for use in IExtendedProperties.Properties are represented in Mediachase.MetaDataPlus.Configurator.MetaDataType.
MetaDataType type – .NET type
MetaDataType.DateTime–DateTimeMetaDataType.Date–DateTimeMetaDataType.DictionarySingleValue–MetaDictionaryItemMetaDataType.EnumSingleValue–MetaDictionaryItemMetaDataType.Float–doubleMetaDataType.Decimal–decimalMetaDataType.Money–decimalMetaDataType.Integer–intMetaDataType.DictionaryMultiValue–MetaDictionaryItem[]MetaDataType.EnumMultiValue–MetaDictionaryItem[]MetaDataType.StringDictionary–MetaStringDictionaryMetaDataType.Boolean–boolMetaDataType.Email–stringMetaDataType.URL–stringMetaDataType.ShortString–stringMetaDataType.LongString–stringMetaDataType.LongHtmlString–stringMetaDataType.File–MetaFileMetaDataType.ImageFile–MetaFile
Access order metadata
When determining if an object has extended properties, see if the interface derives from EPiServer.Commerce.Storage.IExtendedProperties.
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart<ICart>(contactId, "Default");
var cartField = cart.Propeties["myfield"].ToString();
var formField = cart.GetFirstForm().Properties["myFormField"].ToString();
var paymentField = cart.GetFirstForm().Payments.First().Properties["myPaymentField"].ToString();
var shipmentField = cart.GetFirstShipment().Properties["myShipmentField"].ToString();
var lineItemField = cart.GetAllLineItems().First().Properties["myLineItemField"].ToString();Set order metadata
When determining if an object has extended properties, see if the interface derives from EPiServer.Commerce.Storage.IExtendedProperties.
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart<ICart>(contactId, "Default");
cart.Propeties["myfield"] = "hello";
cart.GetFirstForm().Properties["myFormField"] = 23 m;
cart.GetFirstForm().Payments.First().Properties["myPaymentField"] = 11;
cart.GetFirstShipment().Properties["myShipmentField"] = 9;
cart.GetAllLineItems().First().Properties["myLineItemField"] = "yes";Access order metadata (legacy)
To access order meta-objects, each order meta-class has a dictionary of meta-fields accessible by the root object. The following example shows how to access meta-fields from different order meta-objects.
Cart newCart = OrderContext.Current.GetCart("myname", newCustomer);
//This is the meta field data access
string myCartField = newCart["myField"].ToString();
string orderformField = newCart.OrderForms[0]["myOrderFormField"].ToString();
string paymentField = newCart.OrderForms[0].Payments[0]["myPaymentField"].ToString();
string shipmentField = newCart.OrderForms[0].Shipments[0]["myShipmentField"].ToString();Updated 22 days ago
