Uncategorized

Extending mapped order entity in storefront

Each Sitecore commerce (SXC) entity has a representation, known as MappedEntity, in the storefront e.g. Cart entity of Commerce Engine(CE) has a corresponding Sitecore.Commerce.Entities.Carts.Cart in Storefront. CE allows the extension of these entities through components.

Mapped entities are part of commerce connect core layer. This layer plays a connection role between storefront repositories and commerce engine APIs.

Most of the time in our projects, we extend these CE entities with custom components. These custom components will have no corresponding mapped components in Storefront. For instance, if you add a customer’s personal details component in order, this component will be exposed as an object property to the storefront. If you want to have a strongly typed representation of that component in your storefront, you will need to extend the mapped entity.

Storefront works with commerce connect and commerce connect core to interact with the commerce engine. A simplified version of this communication would look something like

StorefrontH

I have highlighted the model initializer, this is where we can map the attributes of a CE entity to a mapped entity. Since mapped entities have no clue about the custom components, we need to extend them and then use those extensions to map the attributes.

I am using an example of an order entity. I introduced a customer’s personal details component in that order entity in CE. When I get the order using commerce connect, the mapped order entity has no clue about this new component. So I created an extension of the order mapped entity

Then in the initialize method of the rendering model

If you are interested in the details of rendering model initialization, have a look at any existing CXA rendering. order.GetPropertyValue is a bit interesting thing here. All the components that we add to CE entities are exposed as a collection of objects. The Order entity I used in this example has the following inheritance hierarchy

Order inherits Cart inherits BaseCart inherits MappedEntity inherits Entity. If you look at the Entity class on top, it has properties collection as objects

 

Happy koding 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *