
April 25th 2023
Context:
Last year, I worked with a customer on building a Global Search Feature that combines Content and Products in the results page.
This feature was built using Sitecore XP/XC 9.3 and SXA.
More details on that implementation here.
Recently, the customer decided to Migrate from XC to OrderCloud and upgrade to XM 10.3 while continuing to use SXA.
This brought some questions regarding the recently implemented search feature:
Is there something built-in in Sitecore currently to fulfill this requirement?
Do we need to rewrite the whole feature?
What Gaps do we have to fill in compared to the original implementation?
Sitecore currently offers 2 great search Products:
Sitecore Search : For Content
Sitecore Discover: For Commerce
There is ongoing work to offer a combined solution but no ETA was provided so far.
This means, the pragmatic approach would be to try to reuse as much as possible from the current solution. Especially since it is based on SXA Search API.
Problem:
XP/XC are fully integrated through a Catalog Data Provider that generates Sitecore Items from the Commerce Entities and Indexing Minions that ensure XC Products are being populated in Sitecore Master and Web Indexes.
Moving from XP/XC to XM/OrderCloud means that we will be moving to a Composable Solution where OrderCloud is a separate product/api interacting with Sitecore through custom integration.
The Gap becomes obvious, OrderCloud Products are not available within the Sitecore Indexes.
The next question is also obvious: Is it possible, how much work and what does it take to have OrderCloud Products in Sitecore Indexes.
The answers are Yes, Not that much and the details will be explained below, along with a link to the open-source project in Github.
Solution:
Let's now look closely at what it takes to bring OrderCloud Products to Sitecore Index(es):
1) Full Indexing API Endpoint
First, we need a Full Indexing API Endpoint to perform an initial and on-demand i indexing of all the products from OrderCloud to Sitecore Indexes.
This Endpoint will ideally be part of a middleware application that has access to OrderCloud through Admin API Credentials.
2) Incremental Indexing API Endpoint
Then, we need an Incremental Indexing API to perform updates to the index based on changes happening in OrderCloud.
This API Endpoint will be called from an OrderCloud webhook, triggered by the events below.
3) OrderCloud Indexing Webhook
For Incremental Indexing we need a Webhook in OrderCloud that would call the API whenever one of the following events is triggered:

As you can see I didn't include POST v1/products/{productID} as I don't products created by not associated to a category to be in the Index and thus available for Search. This is an implementation decision on our part. It may not apply to you.
The events above trigger the following results in the Index:
Delete Product Category Assignment -> If it's the only Category that the product belongs to, Remove product from the index.
Create Product Category Assignment -> If it's the first Category that the product belong to, Add the product to the index.
Delete Product -> Remove product from the index.
Update Product (PATCH or PUT) -> Update product in the index.
The incremental indexing API endpoint also expects the IndexName as part of the Configuration Data of the Webhook:

P.S: For simplification I am using only existing fields in the Sitecore Solr Schema. If you want to add custom fields and populate them during indexing, follow this documentation and repopulate your schemas from Sitecore Control Panel.
Installation and Usage:
This project was built using .Net Core 6.
Installation Steps:
Clone the repo here.
Update AppSettings OrderCloudConfiguration and SolrConfiguration:

If running locally use ngrok to start a public tunnel for your localhost api as explained here.
Create the OrderCloud Webhook in the OrderCloud Portal and make it point to the Incremental Indexing API (/IndexingApi/IncrementalProductIndexing). If you're not familiar with Webhooks in OrderCloud, check this.
To run the Full Indexing API (/IndexingApi/FullProductIndexing), you can use Postman or Swagger UI included with the API.
You can now see products in your Sitecore Solr Index with _datasource = 'OrderCloud'. Any updates should also reflect automatically through the webhook and incremental indexing.
Conclusion:
Now that OrderCloud Products are part of Sitecore Solr Index, the next step is to make some minor adjustments/customizations to SXA Search to support OrderCloud datasource.
This will be covered in Part 2 of this blog post series, so Stay tuned.
I hope you find this post helpful. Feel free to leave questions and/or comments.
Comments