Saturday, March 2, 2019

Sitecore Commerce 8.2 -Problem orders for order reconciliation - Notification on email and slack.

Here are a few simple steps to configure a new minion which will run 12 hours and identify the problem statement orders
and will send an email to a configured email id and will send a slack message to a channels.

Step 1  - Configure Environment minion service variables.

    {
        "$type": "Sitecore.Commerce.Core.MinionPolicy, Sitecore.Commerce.Core",
        "WakeupInterval": "12:00:00",
        "ListToWatch": "TestProblemOrders",
        "FullyQualifiedName": "Feature.Commerce.Orders.Engine.Minions.TestProblemOrderReconcileMinion, Feature.Commerce.Orders.Engine",
        "ItemsPerBatch": 100,
        "SleepBetweenBatches": 500
      },
      {
        "$type": "Feature.Commerce.Orders.Engine.Policies.TestProblemOrderReconciliationPolicy, Feature.Commerce.Orders.Engine",
        "NotificationAlertPrefix": "Test Slack Channel Message",
        "ToAddresses": "tesetAddress@test.com",
        "NotificationAddresses": "testNotificationadress@test.com",
        "FromAddressEmailAddress": "fromaddress@test.com",
        "EnabledNotification": true
      },

 Step 2  - Configure Environment minion service variables.

Configure Project/Project.Commerce.Engine/Engine/ConfigureSitecore.cs to register the DI

services.AddTransient();
services.AddTransient();

Setup a class in commerce foundation to send the email notification.

Foundation/Commerce/Infrastructure/Engine/Foundation.Commerce.Infrastructure.Engine/Service/TestSendEmail.cs

Define an interface -

 public interface ISendEmail
    {
        void Send(SmtpClientSettings settings);
    }

Class implementation -

public class TestSendEmail : ISendEmail
    {
        /// 
        /// Sends the email.
        /// 
        /// The settings.
        public void Send(SmtpClientSettings settings)
        {
            if (settings?.EmailMessage == null)
            {
                return;
            }

            Task emailTask = Task.Run(async () => 
            {
              }

}


Define a policy for all smtp configurations.


 Step 3  - Define a new pipeline interface and class for notification.

using Foundation.Commerce.Infrastructure.Engine.Models;
using Sitecore.Commerce.Core;
using Sitecore.Framework.Pipelines;

namespace Foundation.Commerce.Infrastructure.Engine.Pipelines
{
    [PipelineDisplayName("Foundation.Commerce.Infrastructure.Smtp.Engine.Pipelines.ISendEmailPipeline")]
    public interface ISendEmailPipeline : IPipeline
    {
    }
}

using Foundation.Commerce.Infrastructure.Engine.Models;
using Microsoft.Extensions.Logging;
using Sitecore.Commerce.Core;
using Sitecore.Framework.Pipelines;

namespace Foundation.Commerce.Infrastructure.Engine.Pipelines
{
    public class SendEmailPipeline : CommercePipeline, ISendEmailPipeline
    {
        public SendEmailPipeline(IPipelineConfiguration configuration, ILoggerFactory loggerFactory)
        :base(configuration, loggerFactory)
        {
            
        }
    }
}

 Step 4  - Define pipeline block




namespace Foundation.Commerce.Infrastructure.Engine.Pipelines.Blocks
{

 public class TestSendNotificationBlock : PipelineBlock
    {
        private readonly ISendEmail _sendEmail;

        public SendNotificationBlock(ISendEmail sendEmail)
        {
            this._sendEmail = sendEmail;
        }


   public override async Task Run(NotificationMessage arg, CommercePipelineExecutionContext context)
        {
            if (arg == null || string.IsNullOrWhiteSpace(arg.Description) || string.IsNullOrWhiteSpace(arg.Subject))
            {
                // send email message
               return false;
            }

        }
    }
}

 Step 5  - Create a new minion class for order reconciliation  under /Feature.Commerce.Orders.Engine/Minions



namespace Feature.Commerce.Orders.Engine.Minions
{

    public class ProblemOrderReconcileMinion : Minion
    {
       private ISendEmailPipeline _sendEmailPipeline;

        public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy,
            CommerceEnvironment environment,
            CommerceContext globalContext)
        {
            base.Initialize(serviceProvider, logger, policy, environment, globalContext);
            _sendEmailPipeline = serviceProvider.GetService();
        }

       public override async Task Run()
        {
           var ordersList = await this.GetListItems(this.Policy.ListToWatch, this.Policy.ItemsPerBatch);
           var orders = ordersList as Order[] ?? ordersList.ToArray();
            Logger.LogInformation($"[Problem Order Reconciliation Minion] Problem Orders {orders.Length}", this);

            if (!orders.Any())
            {
                Logger.LogWarning("No Problem Orders Found!");
                return new MinionRunResultsModel() { Name = Name, ItemsProcessed = 0};
            }

            Logger.LogInformation($"[Problem Order Reconciliation Minion] Triggering Send Email Pipeline", this);
            var isMailSent = await _sendEmailPipeline.Run(CreateEmailMessage(orders), this.MinionContext.GetPipelineContextOptions());

            var result = isMailSent ? "Successful" : "Failed";
            Logger.LogInformation($"[Problem Order Reconciliation Minion] Email Status {result}", this);
            return new MinionRunResultsModel() { Name = Name, ItemsProcessed = orders.Count()};
        }
}

that's it, it's very simple to configure the minion service in Sitecore commerce.


Saturday, February 2, 2019

Sitecore commerce - Fix for SolrNet.Exceptions.SolrConnectionException: The operation has timed out.



While rebuilding the indexes, We got below errors -

SolrNet.Exceptions.SolrConnectionException: The operation has timed out

Fix - I have increased the time

Path - C:\inetpub\wwwroot\.dev.local\App_Config\Sitecore\ContentSearch
Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config

This is the default setting



We have updated the value to 600000 and it resolved the issue.

Result -




Friday, February 1, 2019

Sitecore Commerce 8.2 - Monitor Minion Services.



Basically for the Sitecore commerece a window service is running the minion service.

Service Recovery Setting

Windows services provides an option to decide what to do when the service fails. It can restart the service, run another program or restart the machine itself.


The recovery settings can be set to restart the service on 1st and 2nd failure and any subsequent fails will trigger a script which can perform any preferred actions:

  1. Send email / SMS
  2. Call a service
  3. Send a slack message Etc.

Bash script monitoring the service

There are several ways to monitor multiple services and provides some visualization on that as well as perform some action based on the state of the service.

With PowerShell we can get the list of services we want and check their status in an interval and either output it or perform an action. The following blog has a sample script which can help with this approach.

https://gallery.technet.microsoft.com/scriptcenter/Monitor-Report-5d1998d4

There are many commercial or free external tools which provides monitoring on Windows services as well.

Saturday, January 26, 2019

Sitecore commere - Can't see any item in search


If you can't see any product in the SXA -

Fix - Reindexing for master and web index have resolved the issue.


after reindex, I can see the result



Sunday, January 20, 2019

Sitecore commerece - Fix for Install-SitecoreConfiguration : The service cannot accept control messages at this time.



Error - Install-SitecoreConfiguration : The service cannot accept control messages at this time. (Exception from HRESULT: 0x80070425)
At C:\deploy\SIF.Sitecore.Commerce.3.0.28\Deploy-Sitecore-Commerce.ps1:95 char:1
+ Install-SitecoreConfiguration @params -Verbose *>&1 | Tee-Object "$PS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Install-SitecoreConfiguration

[TIME] 00:03:57
Invoke-ManageAppPoolTask : The service cannot accept control messages at this time. (Exception from HRESULT: 0x80070425)
At C:\Program Files\WindowsPowerShell\Modules\SitecoreInstallFramework\2.1.0\Public\Install-SitecoreConfiguration.ps1:641 char:25
+                         & $entry.Task.Command @paramSet | Out-Default
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ManageAppPoolTask

Fix -

Please make sure you are not accessing any SXA site locally, Stop and restart the IIS, Please check all window services related to Sitecore has stopped.

Friday, January 18, 2019

Sitecore Commerce - Fix for Index rebuild failure

While rebuilding the web index for the commerce instance which contained a number of categories and sellable items,

We got the below error -

Exception: System.NullReferenceExceptionMessage: Object reference not set to an instance of an object.Source:
 Sitecore.Commerce.Engine.Connectat Sitecore.Commerce.Engine.Connect.Search.Crawlers.CatalogCrawlerBase`1.<>c__DisplayClass52_1.
b__0(CommerceCatalogIndexableItem indexable, ParallelLoopState loopState)

Fix - 

Open the content editor update the data commerce template and clearing the cache, this will fix the index rebuild issue.

Saturday, January 12, 2019

Sitecore commerce - Fix for the property 'Value' cannot be found on this object. Verify that the property exists.



[-------------------- CommerceEngine-Ops_CreateWebsiteForMinion [Skipped] : Website ----------------------------------------------------------------]

[----------------------------------------- CommerceEngine-Ops_StopWebsite : ManageWebsite ----------------------------------------------------------]
VERBOSE: Stops the website if it is running.
[CommerceEngine-Ops_StopWebsite]:[Stop] CommerceOps_Sc9
VERBOSE: Performing the operation "Stop-Website" on target "CommerceOps_Sc9".
VERBOSE: Checking state of Website 'CommerceOps_Sc9'
Install-SitecoreConfiguration : The property 'Value' cannot be found on this object. Verify that the property exists.
At C:\deploy\SIF.Sitecore.Commerce.3.0.28\Deploy-Sitecore-Commerce.ps1:95 char:1
+ Install-SitecoreConfiguration @params -Verbose *>&1 | Tee-Object "$PS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Install-SitecoreConfiguration

[TIME] 00:00:52
Invoke-ManageWebsiteTask : The property 'Value' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\SitecoreInstallFramework\2.1.0\Public\Install-SitecoreConfiguration.ps1:641 char:25
+                         & $entry.Task.Command @paramSet | Out-Default
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ManageWebsiteTask

PS C:\deploy\SIF.Sitecore.Commerce.3.0.28>

FIx - In my case, my IIS was stop, I have restarted by IIS and it resolved the issue.