Virtual attributes allow you to extend the capabilities of the Integration API.
Virtual attributes are not part of the type sytem for the type that the Integration Object Item references, but they can be added and configured as part of a type and defined in an Integration Object Item. You can create virtual attributes for Integration Object Items and add them at runtime. This means that you can add an additional attribute without needing to update the items.xml file, then restart and re-initialize SAP Commerce Cloud, which saves valuable time.
Virtual attributes offer the following advantages:
Data formatting – For example, dates and numbers.
Payload Enrichment – Adding details that may not exist on the Item Type. For example, append a list of coupon codes to a product.
Payload Flattening – Customize the payload to reduce the number of nested objects. For example, Customer and Address.
Virtual attributes do not support auto-create; cannot be part of an integration key (no option to configure them as unique); and require unique names within Integration Object Items that do not conflict with existing standard or classification attribute names.
Virtual attributes support only primitive types. The following are supported:
java.lang.Integer
java.lang.Boolean
java.lang.Byte
java.lang.Double
java.lang.Float
java.lang.Long
java.lang.Short
java.lang.String
java.lang.Character
java.util.Date
java.math.BigInteger
java.math.BigDecimal
Configuring Virtual Attributes
Virtual attributes use the following two types: IntegrationObjectItemVirtualAttribute and IntegrationObjectVirtualAttributeDescriptor. retrievalDescriptor is a required field in IntegrationObjectItemVirtualAttribute.
Virtual Attributes via impEX
The following example creates an Integration Object (VirtualAttributeIO) with an Integration Object Item that includes a virtual attribute named myVirtualAttribute1 associated with it.
Load the following ImpEX:
Run the following GET request to get the Integration Object metadata: https://localhost:9002/odata2webservices/VirtualAttributeIO/$metadata
The following EDMX schema containing the virtual attribute myVirtualAttribute1 is returned (similar to the other attributes):
Virtual Attributes via Meta API
The following example creates an Integration Object (VirtualAtributeIO) containing the virtual attribute virtualName associated with it.
POST to https://localhost:9002/odata2webservices/IntegrationService/IntegrationObjects with the following body:
Make a GET request to https://localhost:9002/odata2webservices/VirtualAttributeIO/$metadata and obtain the following EDMX: