August 22nd 2023
In this previous post we started discussing how we can use Sitecore SXA Search to return both Content and Commerce items in the context of XM/OrderCloud implementation.
We went through the first step, that allowed us to index OrderCloud Products through Full and Incremental Indexing APIs, leveraging OrderCloud Webhooks.
Now that we have OrderCloud products in the same sitecore index(es), next step is to make sure SXA API returns these products in the results endpoint.
This is the subject of this new blog post.
Reminder: During the indexing step we used datasource = "OrderCloud" to identify products coming from OrderCloud. Sitecore content is indexed using datasource = "Sitecore".
Looking at OOB SXA Search, we can see that it's calling GetItem to get the result items from Sitecore. In our case, this was not needed as Solr Index had all the fields we needed to display, so we used this customization opportunity to remove this GetItem call and improve overall performance of the API. I strongly suggest you do the same.
Since Products are coming from OrderCloud and not Sitecore, GetItem will pose a problem, and that's the main reason for this customization.
Implementation details:
Using DotPeek or any other decompiler, you can see that the OOB implementation consists into 3 main steps:
1-Building the Query
2-Getting Search Results - (This step is returning Sitecore Items)
3-Building the result set output
The first thing we need to do as part of the customization is to override step 2 to make return a list of Search Results without converting them into Sitecore Items. (Using ContentPage type instead of SearchResult)
Then simply override Step 3 to build the result set output based on the Search Results and not Items.
You can find the full implementation in the Guithub repo here.
N.B: This is a simple implementation to showcase end to end process to get OrderCloud Products indexed and searchable using SXA. You might need to add more fields like List Price, Sale Price, Currency... to make this more efficient.
I hope you find this post helpful. Feel free to leave questions and/or comments.
Commentaires