Monday, July 29, 2019

Install-SitecoreConfiguration : CertEnroll::CSignerCertificate::Initialize: Cannot find object or property. 0x80092004

Recently while installing Sitecore Experience Commerce 9 Update 2 (SitecoreXC9.02) I got the below error:

Install-SitecoreConfiguration : CertEnroll::CSignerCertificate::Initialize: Cannot find object or property. 0x80092004 (-2146885628 CRYPT_E_NOT_FOUND)



When googling this error the most prominent blog that shows up is this but unfortunately, in my scenario, it was not helpful.

The problem ended up due to the SIF version that I had. By default, the latest version of SIF gets picked up which is (as of the day I am writing this article) 2.1.0 but for Sitecore 9 commerce update 2 (SitecoreXC9.02), we need SIF 1.2.1. Not sure if this is mentioned anywhere in Sitecore documentation. 

So I had to force PowerShell to use the older version of SIF using the method explained here and re-ran the installation. It at least got me past this certificate issue. 

Monday, March 11, 2019

Hiding default SXA rendering styles in cloned SXA renderings

For our project, we clone existing SXA renderings and customize to the designs. While doing so what I noticed is that certain default styles show up along with the custom styles created as per the design.

The client didn't like the idea of the unwanted styles showing up so had to hide that and show only the custom ones which can be used. Below snapshot shows the styles that needs hiding.


On investigating further I found that the styles to be shown on the control properties dialog is based on the Allowed Renderings field in the style template. If there is nothing selected in the Allowed renderings for a style it would show up on all the renderings properties.

So to achieve what we wanted I had below two options:

  1. List all the OOTB SXA components in Allowed renderings for the styles that show for all the components.  This to me is not an elegant solution
  2. Add a custom field for Disallowed renderings and write a custom pipeline to use the new field. 
I went with option 2. 

First thing I had to do is to figure out the pipeline responsible for showing the styles in the control properties. From the showconfig, I figured that below pipeline processors are 


<getStyles patch:source="Sitecore.XA.Foundation.Presentation.config">
<processor type="Sitecore.XA.Foundation.Presentation.Pipelines.GetStyles.GetSiteStyles, Sitecore.XA.Foundation.Presentation" resolve="true"/>
<processor type="Sitecore.XA.Foundation.Presentation.Pipelines.GetStyles.GetSharedStyles, Sitecore.XA.Foundation.Presentation" resolve="true"/>
</getStyles>

So I had to override the GetSiteStyles processor for our purpose. Below is the config patch file I created to patch the GetSiteStyles processor.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <getStyles>
        <processor type="xxxxx.Common.Pipeline.GetSiteStyles,xxxxx.Common" 
                   patch:instead="*[@type='Sitecore.XA.Foundation.Presentation.Pipelines.GetStyles.GetSiteStyles, Sitecore.XA.Foundation.Presentation']" 
                    resolve="true" />
      </getStyles>
    </pipelines>
  </sitecore>
</configuration>

Introduced a new field called "Disallowed Renderings", which is a duplicate of Allowed Renderings field, to /sitecore/templates/Foundation/Experience Accelerator/Presentation/Style template 

Then I copied over the code for GetSiteStyles to my solution using dotPeek and modified it to handle the new field to not show the styles for renderings which are selected in Disallowed renderings. 

Below is the code for the custom processor.

using Sitecore.Data;
using Sitecore.Data.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore.XA.Foundation.Presentation;
using Sitecore.XA.Foundation.Presentation.Pipelines.GetStyles;

namespace xxxxx.Common.Pipeline
{
    public class GetSiteStyles : GetStylesProcessorBase
    {
        private readonly IPresentationContext _presentationContext;

        public GetSiteStyles(IPresentationContext presentationContext)
        {
            this._presentationContext = presentationContext;
        }

        public void Process(GetStylesArgs args)
        {
            if (string.IsNullOrEmpty(args.Rendering))
                return;
            ItemUri renderingItemUri = new ItemUri(args.Rendering);
            Item stylesItem = this._presentationContext.GetStylesItem(args.ContextItem);
            if (stylesItem == null)
                return;
            args.Styles = (IList<Item>)args.Styles.Concat<Item>(((IEnumerable<Item>)stylesItem.Axes.GetDescendants()).Where<Item>((Func<Item, bool>)(i =>
            {
                if (this.IsStyleItem(i))
                {
                    if(!IsDisAllowed(i, renderingItemUri))
                    {
                        return this.IsAllowed(i, renderingItemUri);
                    }
                }
                return false;
            }))).ToList<Item>();
        }

        public static ID DisAllowedControls { get; } = new ID("{C118A21A-6E60-4AAA-93F4-0A64FDA344E2}");

        protected virtual bool IsDisAllowed(Item styleItem, ItemUri renderingItemUri)
        {
            string str = styleItem[DisAllowedControls];
            if (str != "")
                return str.Contains(renderingItemUri.ItemID.ToString());
            return false;
        }
    }
}

After doing the above stuff I could select my custom rendering in the Disallowed renderings field for the Style that showed up by default like shown in the picture below:



After this below is how the control properties showed with only the custom styles. 

Problem Solved! 





Monday, February 25, 2019

Assigning a rendering variant to a custom SXA rendering

We had to clone an existing SXA component and use it with custom HTML and Styling. In our case, we chose the carousel component as we needed an ability to add Tiles the way we add slides in the carousel SXA component.

Carousel component uses Page Content (/sitecore/layout/Renderings/Feature/Experience Accelerator/Page Content/Page Content) rendering for the Slide which uses Rendering variants for rendering the components.

I had to clone the Page Content rendering also as the mark-up it used didn't match our designs. Now the problem I faced is that the "clone of the Page Content" rendering was not able to find its rendering variants. BTW, here I should mention that the Rendering Variants are expected to show up in a drop down of the component properties which is based on {936D40D8-E317-4A33-9F66-E65E9FF51845}.

After getting deeper into this problem I found how the rendering variants are populated for a rendering. It is based on the getVariants pipeline which in turn calls four processor's as shown in the snapshot below. You can see this in the showconfig.aspx


Below is what each processor of this pipeline does:

1. First processor looks for System Variants under {F9814DDD-B646-469D-9E22-E0E867730B7B} which is /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants. Where is looks for variants under variant definition which has the same name as the rendering item

2. Second processor looks for Site variants under /sitecore/content/Sitecore/[Site name]/Presentation/Rendering Variants/{Rendering Name}

3. Third, based on the compatible rendering mentioned in the rendering variant

4. Fourth, it says GetSharedVariants. I am not too sure about this processor at the moment but I would come back and edit this post once I find out.

Ideally, I would have preferred the 2nd option to work so that I can keep the rendering variants grouped by the site but somehow it didn't but the first option worked. So now I have my custom rendering variant under /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants

Wednesday, November 14, 2018

Status Code: 401; Unauthorized - while communicating with Sitecore commerce API

While working on Sitecore commerce 9, I was getting the below exception:

Exception: Microsoft.OData.Client.DataServiceClientException
Message: Status Code: 401; Unauthorized                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
Source: Microsoft.OData.Client
   at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)

   at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)

The exception message was misleading as it conveyed that there is something wrong with the certificate thumbprint and communication between the website and commerce is not working as expected. 

After digging into logs from commerce authoring environment found that the exception was because one of the stored procedure was missing. After installing the SP was able to resolve this exception. 

So the idea is that the exceptions thrown while interacting with Sitecore commerce can be misleading. To get to the root cause check the logs on the commerce engine web apps. 


Tuesday, July 3, 2018

Shop '*' does not exist.","CommerceTermKey":"InvalidShop"

"@odata.context":"https://localhost:5000/Api/$metadata#Sitecore.Commerce.Core.CommandMessage","MessageDate":"2018-04 10T10:03:59.2415572Z","Code":"Error","Text":"Shop 'CommerceEngineDefaultStorefront' does not exist.","CommerceTermKey":"InvalidShop"

If you are seeing the above error in BizFx, below are the things to check:

  1. Make sure that the defaultShopName in the Sitecore.Commerce.Engine.Connect.config matches with the shop name under /sitecore/Commerce/Commerce Control Panel/Storefront Settings/Storefronts. 
  2. If the above step doesn't help, check /site/wwwroot/wwwroot/data/Environments/PlugIn.Content.PolicySet-1.0.0.json. Make sure that the hostname and Sitecore credentials in this config file is correct as Sitecore uses this details to make API calls for Sitecore items. If you have to make changes to this config file you would have to do commerce bootstrap to see that the changes in effect. 
  3. If all the information in /site/wwwroot/wwwroot/data/Environments/PlugIn.Content.PolicySet-1.0.0.json is correct and still you are getting the same error, release the boostrap process and restart the commerce webapps / IIS site. 



Thursday, May 17, 2018

Sitecore commerce BizFx on Azure PaaS throws 403 forbidden error in console.

After setting up Sitecore commerce on Azure PaaS, I got the below 403 forbidden error when getting to Business tools.




On digging into the logs further we found the below:

11 06:45:02 INFO Authorization was successful for user: "sitecore\Admin".
11 06:45:02 ERROR CommerceController.OnActionExecuting.Forbidden: User not allowed for action /api/GetNavigationView()

This is because Commerce related roles were missing in the Azure PaaS web app. Below two roles are required to access the commerce business tools.

sitecore\Commerce Administrator
sitecore\Commerce Business User

These roles were available on my local laptop setup but not on Azure WebApp. After packaging this from local and deploy to Azure WebApp we got past the 403 Forbidden error.

Monday, March 19, 2018

Sitecore 9 commerce install fails while running "Get Token From Sitecore.IdentityServer" Step

Sitecore 9 commerce install PS fails as "GetIdServerToken : GetIdServerToken" step with below exception:


HTTP Error 500.19 - Internal Server Error
  The requested page cannot be accessed because the related configuration data for the page is invalid.



 Detailed Error Information:


    Module&nbsp;&nbsp;&nbsp;IIS Web Core
    Notification&nbsp;&nbsp;&nbsp;Unknown
    Handler&nbsp;&nbsp;&nbsp;Not yet determined
    Error Code&nbsp;&nbsp;&nbsp;0x8007000d
    Config Error&nbsp;&nbsp;&nbsp;
Config File&nbsp;&nbsp;&nbsp;\\?\C:\inetpub\wwwroot\SitecoreIdentityServer\web.config




    Requested URL&nbsp;&nbsp;&nbsp;https://localhost:5050/connect/token
    Physical Path&nbsp;&nbsp;&nbsp;
    Logon Method&nbsp;&nbsp;&nbsp;Not yet determined
    Logon User&nbsp;&nbsp;&nbsp;Not yet determined 


    Config Source:
       -1:
    0: 


 More Information:
  This error occurs when there is a problem reading the configuration file for the Web server or Web application. In
some cases, the event logs may contain more information about what caused this error.
  View more information &raquo; 

At C:\Program
Files\WindowsPowerShell\Modules\SitecoreInstallFramework\1.2.0\Public\Install-SitecoreConfiguration.ps1:253 char:21
+                     & $entry.Task.Command @paramSet | Out-Default
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Install-SitecoreConfiguration


To fix this, follow the below steps:

1. Make sure .NET Core SDK 2.x (https://www.microsoft.com/net/download/windows) is installed
2. Install Dotnetcore-2-windowshosting (https://aka.ms/dotnetcore-2-windowshosting) 
3. If the above installation was already done but before the IIS was installed, run a repair on the installation. 

To make sure the installation of DotNetCore is done as expected, open the Handler mapping in IIS for SitecoreIdentityServer and make sure you see aspNetCore module listed.


Rerun the Commerce installation. 

Hope this helps!