Tuesday, July 10, 2018

Sitecore Experience Commerce - Management.GetCommerceTerms and related methods in logs

Looking at the logs for a long running Sitecore Experience Commerce minion, I noticed large chunks of the following logs:
INFO Management.GetCommerceTerms./sitecore/Commerce/Commerce Control Panel/Commerce Engine Settings/Commerce Terms/BusinessTools/ViewPropertyNames|en
INFO Management.block.getitemsbypath./sitecore/Commerce/Commerce Control Panel/Commerce Engine Settings/Commerce Terms/BusinessTools/ViewPropertyNames|en
INFO Management.block.getitembyid.7f475f9d-341e-4a21-bec2-0f5f74987a3b: Language=en
It turns out that my minions environment (and the Habitat example) did not enable caching for queries related to management. For example the OOTB Habitat minions experience commerce environment (defined in PlugIn.Habitat.CommerceMinions-1.0.0.json) references a PolicySetId of Entity-PolicySet-MinionsMemoryCachePolicySet which in turn is defined in PlugIn.MinionsMemoryCache.PolicySet-1.0.0.json.

To allow caching of these management related queries, the following can be added to the PlugIn.MinionsMemoryCache.PolicySet-1.0.0.json file (or your own custom version).
{
  "@odata.type": "Sitecore.Commerce.Plugin.Management.ManagementCachePolicy, Sitecore.Commerce.Plugin.Management",
  "AllowCaching": true,
  "Expiration": 3600000
},
It may appear more cut-down than other caching examples, but worked in my environment.

Extract of a caching policy for a Sitecore Experience Commerce engine environment

Monday, July 9, 2018

Sitecore SOLR - unknown field MyFieldName

After adding a new computed index field to my SOLR web index, I was getting the following error on rebuild:
Job started: Index_Update_IndexName=sitecore_web_index|#Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> SolrNet.Exceptions.SolrConnectionException: <?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int name="QTime">1</int></lst><lst name="error"><lst name="metadata"><str name="error-class">org.apache.solr.common.SolrException</str><str name="root-error-class">org.apache.solr.common.SolrException</str></lst><str name="msg">ERROR: [doc=sitecore://web/{57606db8-1237-463b-a934-01f3854a2909}?lang=en&amp;ver=0&amp;ndx=sitecore_web_index] unknown field 'MyFieldName'</str><int name="code">400</int></lst>
</response>
 ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
This is due to the fact that when I added the field to the index, the returnType was set as:
returnType="System.Double"
Where it should have been set as:
returnType="double"
This data return type is mapped on the SOLR field map:
Sitecore SOLR Field Map

Wednesday, July 4, 2018

Sitecore Experience Commerce - ERROR Site Disabled. Failed to logging

In a Sitecore Experience Commerce environment running the minions role, the following set of errors would occur when attempting to access an item in Sitecore.
17 19:13:17 INFO Management.block.getitembyid.0F65742E-317F-44B0-A4DE-EBF06209E8EE: Language=en
17 19:13:17 ERROR SitecoreConnectionManager: RETRY 1 out of 3 with ERROR Site Disabled. Failed to logging. /sitecore/api/ssc/auth/login for GET /sitecore/api/ssc/item/0F65742E-317F-44B0-A4DE-EBF06209E8EE?database=master&language=en
17 19:13:17 ERROR SitecoreConnectionManager: RETRY 2 out of 3 with ERROR Site Disabled. Failed to logging. /sitecore/api/ssc/auth/login for GET /sitecore/api/ssc/item/0F65742E-317F-44B0-A4DE-EBF06209E8EE?database=master&language=en
17 19:13:17 ERROR SitecoreConnectionManager: RETRY 3 out of 3 with ERROR Site Disabled. Failed to logging. /sitecore/api/ssc/auth/login for GET /sitecore/api/ssc/item/0F65742E-317F-44B0-A4DE-EBF06209E8EE?database=master&language=en
17 19:13:17 ERROR SitecoreConnectionManager.Error: Message=RETRY FAILED for GET /sitecore/api/ssc/item/0F65742E-317F-44B0-A4DE-EBF06209E8EE?database=master&language=en|Trace=   at Sitecore.Commerce.Plugin.Management.SitecoreConnectionManager.ProcessRequest(CommerceContext commerceContext, String action, String method, ItemModel itemModel)
System.Exception: RETRY FAILED for GET /sitecore/api/ssc/item/0F65742E-317F-44B0-A4DE-EBF06209E8EE?database=master&language=en
   at Sitecore.Commerce.Plugin.Management.SitecoreConnectionManager.ProcessRequest(CommerceContext commerceContext, String action, String method, ItemModel itemModel)
17 19:13:17 ERROR Management.block.getitembyid: Sitecore Item Service Get item failed, Item 0F65742E-317F-44B0-A4DE-EBF06209E8EE not found.
I had checked the configuration file along with the content set policy (PlugIn.Content.PolicySet-1.0.0.json) and all connection details and user accounts were correct for the Sitecore instance.\\

It turned out that this error was occurring because the minion experience commerce engine role was blocked from accessing the Sitecore content management instance due to an IP white listing rule.

Tuesday, July 3, 2018

Sitecore Experience Commerce - Facets are limited to 100 results

I was debugging a Sitecore Experience Commerce product list locally (using SOLR as a search provider) and noticed that a category with a large number of brands to facet on, would always limit out at 100 results. This was not ideal as that 100 would include facets with 0 aggregate count (matches for a given search) which meant actual brands that were in the results would not appear as a valid facet.

This turned out to be a default setting with SOLR whereby the maximum number of facets to return for a given query was 100. This can be increased to a valid number as required or to unlimited with a setting of -1.

To increase the number of facets to return with a SOLR index in Sitecore, you will need to do the following.

  1. In the SOLR directory locate the index you wish to target.
    1. In my case this was the web index - which is located in C:\solr\server\solr\sc_web_index
  2. Inside the conf child director is a solrconfig.xml configuration file.
  3. The facet.limit setting needs to be edited - in my case this setting was not present
    1. A valid number to set a hard limit of facets to return or -1 for unlimited.
  4. Add or edit the setting in the following location.
  5. Restart the SOLR service.
<requestHandler name="/select" class="solr.SearchHandler">
<!-- default values for query parameters can be specified, these
  will be overridden by parameters in the request
  -->
<lst name="defaults">
  <str name="echoParams">explicit</str>
  <int name="rows">10</int>
  <str name="facet.limit">-1</str>

Note: the snippet has been cut-down, however there is enough here to see where to add the setting.

After making this change, I was now seeing all of the brand facet data that I was expecting.