Extend a Commerce view to show additional information in the Business Tools
Current version: 9.3
You can extend a Commerce view to show additional information in the Sitecore XC Business Tools user interface. The following is an example of how you can extend an Entity View to display the summary of points that have been earned on the Order Details page. We extend the view by adding a new EntityView
block.
To extend a commerce view to show additional information:
-
Copy and paste the sample block and name it
GetOrderSummaryViewBlock
. -
The
GetEntityView
blocks take anEntityView
as a parameter and return anEntityView
. Because this extension must see an order, you must add a reference to the Orders plugin, for example:RequestResponseshellSitecore.Commerce.Plugin.Orders": "1.0.2301
-
Add the new block:
RequestResponseshellif (request.ViewName != context.GetPolicy<KnownOrderViewsPolicy>().Summary && request.ViewName != context.GetPolicy<KnownOrderViewsPolicy>().Master) { // Do nothing if this request is for a different view return Task.FromResult(entityView); } if (request.Entity == null) { // Do nothing if there is no entity loaded return Task.FromResult(entityView); } // Only do something if the Entity is an order if (!(request.Entity is Order)) { return Task.FromResult(entityView); } var order = request.Entity as Order; EntityView entityViewToProcess; if (request.ViewName == context.GetPolicy<KnownOrderViewsPolicy>().Master) { entityViewToProcess = entityView.ChildViews.FirstOrDefault(p=>p.Name == "Summary") as EntityView; } else { entityViewToProcess = entityView; } int pointsEarned = 0; foreach(var line in order.Lines.Where(p=>p.HasComponent<LoyaltyComponent>())) { pointsEarned = pointsEarned + line.GetComponent<LoyaltyComponent>().Points; } entityViewToProcess.Properties.Add(new ViewProperty { Name = "Points Earned", IsReadOnly = true, RawValue = pointsEarned }); return Task.FromResult(entityView);