Tuesday, March 6, 2018

Sitecore Experience Commerce - Plugin to extend commerce entity not showing in business tools

After creating a plugin to extend the PriceCard commerce entity in Sitecore Experience Commerce, I noticed that my new section was not showing when viewing a PriceCard in commerce business tools.

The first step was to go into Postman and run the Ops Metadata service call - {{OpsApiHost}}/{{OpsApi}}/$metadata. Here I was able to compare a working plugin:
<Schema Namespace="Plugin.MyProject.SaleType" xmlns="http://docs.oasis-open.org/odata/ns/edm">
 <ComplexType Name="KnownSaleTypeActionsPolicy" BaseType="Sitecore.Commerce.Core.Policy">
  <Property Name="EditSaleType" Type="Edm.String" />
 <ComplexType Name="KnownSaleTypeViewsPolicy" BaseType="Sitecore.Commerce.Core.Policy">
  <Property Name="SaleType" Type="Edm.String" />
 <EntityType Name="SaleTypeComponents" BaseType="Sitecore.Commerce.Core.Component">
  <Property Name="SaleType" Type="Edm.String" />
  <Property Name="MinOrderQuantity" Type="Edm.String" />
  <Property Name="OrderStepSize" Type="Edm.String" />
  <Property Name="OrderStepUom" Type="Edm.String" />
To one that was not working:
<Schema Namespace="Plugin.MyProject.PriceDetail.Policies" xmlns="http://docs.oasis-open.org/odata/ns/edm">
 <ComplexType Name="PriceDetailActionsPolicy" BaseType="Sitecore.Commerce.Core.Policy">
  <Property Name="EditPriceDetail" Type="Edm.String" />
 <ComplexType Name="PriceDetailViewsPolicy" BaseType="Sitecore.Commerce.Core.Policy">
  <Property Name="PriceDetail" Type="Edm.String" />
Notice that the EntityType section was missing. To fix this problem, I check my Components, Pipelines and policies and noticed in the broken example, namespaces were full written out. For example I had used:
namespace Plugin.MyProject.PriceDetail.Pipelines.Blocks.DoActions
Instead of simply:
namespace Plugin.MyProject.PriceDetail
Fixing this allowed the EntityType section to appear as expected, but not the section to appear in the business tools. What was stopping this from happening was a line in the ConfigureSitecore code:
Was incorrect (notice self reference) and instead should have been:
This is a good case for always following a template that works and when it doesn't compare against one which does.

No comments:

Post a Comment