Friday, May 26, 2017

Sitecore Commerce catalog web service error

When attempting to load up Sitecore's commerce server catalog manager, the following error may occur when attempting to connect.
The Catalog Web Service is currently unavailable. The web service might be experiencing technical difficulties, or you may need to adjust your connection settings.
 It often occurs when the URL of the service inside the connection was incorrect. Ensure you are using the correct base URL and that the path in fact leads to the web service. In the example image above, part of the URL is incorrect. It should have been Habitat_CatalogWebService instead of HabitatCatalogWebService.

Thursday, May 25, 2017

Sitecore Demo Retail install sites issues

At the time of writing the Sitecore Demo Retail project, it is not possible to spin up the solution with visual studio 2017 installed on the machine. At the top of the wiki, the following notice appears:
Important Note
Visual Studio 2015 is required for this solution. Installing Visual Studio 2017 alongside will cause issues with .NET Core dependencies and will prevent the solution from deploying correctly
If you attempt to install the solution (with visual studio 2017)), a number of errors may happen during the install PowerShell script. These generally happen when MSBuild is attempting to build solutions.
C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce.Entitlements\Engine.Entitlements\Sitecore.Foundation.Commerce.
Engine.Plugin.Entitlements.xproj(7,3): error MSB4019: The imported project "
C:\Program Files\dotnet\sdk\1.0.4\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path
 in the <Import> declaration is correct, and that the file exists on disk.
 C:\Projects\Sitecore.Demo.Retail\src\Project\Retail\code\Sitecore.Demo.Retail.csproj(197,3): error MSB4019:
The imported project "C:\ProgramFiles\dotnet\sdk\1.0.4\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found.
 C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\Sitecore.Foundation.Commerce.Engine.xproj : error  :
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\Sitecore.Foundation.Commerce.Engine.xproj
C:\Users\ryanb\.nuget\packages\baseclass.contrib.nuget.output\2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets(
73,5): error MSB4801: The task factory "CodeTaskFactory" could not be loaded because this version of MSBuild does not
support it. [C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\Engine.csproj]
These errors occur for two reasons:
  1. Visual Studio 2017 needs to be uninstalled
  2. Any other versions of the .NET core need to be uninstalled. The instructions (at time of writing) specify .NET Core 1.0.3 SDK Preview 2 build 3156.

Wednesday, May 24, 2017

Sitecore Demo Retail installation error

After pulling down Sitecore Demo Retail, and attempting to deploy it over Habitat, a couple errors came up during the install-commerce-sites PowerShell script. This one occurred during step 6
Invoke-Sqlcmd : Cannot drop the database 'demo.local_SitecoreCommerce.SharedEnvironments', because it does not exist or you do not have permission.

It traced back to one of the scripts being run: ManageSqlServer.psm1. The line where the dacservice for SQL server was originally the following:
$dacService = new-object Microsoft.SqlServer.Dac.DacServices "server=$server"
Updating the connection string to use windows credentials then allowed it to run correctly.
$dacService = new-object Microsoft.SqlServer.Dac.DacServices "server=$server;Integrated Security = True;"


Tuesday, May 23, 2017

Sitecore site gives a 503 service unavailable message

When attempting to load a Sitecore 8.2 instance on my local machine, the front-end site and Sitecore administration site were returning an error:
HTTP Error 503. The service is unavailable.
An IIS Reset did not appear to fix the issue and the Sitecore logs were not showing anything interesting.

It turns out that the application pool for the site was stopped for some reason. Starting this up allowed the web site to load correctly.


Monday, April 3, 2017

Sitecore custom personalization rule with value selection for content editors

Custom personalization rules in Sitecore are a great way of using custom business logic/conditions to build personalized experiences for a web site's users. These rules will often require the content editor to enter a value when creating the rule in the rule builder interface. An example of this might be a rule used to personalize on a user's car make. The rule could be "Where the user's car make is Car Make".

Instead of requiring a content editor to type that car make in (which creates opportunity of user error and creates a rule that can never be true), the rule can instead be configured to allow the content editor to select from a list of predefined values.

How this works is that, in the content tree a parent node will be setup to contain all items which the content editor will select from. Any template can be used, and ultimately it's the item's ID which will be passed to the rule processor.


The rule text will then be defined as:
Where the user's car make is [carMakeID,Tree,root={63A00CEE-0711-42CF-9B40-6B8C81EF6537},Car Make]
 The squared bracketed token contains 4 parameters:
  1. The name of the property in the .NET class for the rule
  2. Tree - indicates this is a tree selection
  3. Root which points to the parent item's ID in the tree. In this case it's the Car Makes folder above.
  4. Text that is displayed in the rule set editor
Now the actual rule processor code:
namespace MyProject
{
    public class CarMakeRule<T> : WhenCondition<T> where T : RuleContext
    {
        // Fields
        private string carMakeID;

        // Methods
        public CarMakeRule()
        {
            carMakeID = string.Empty;
        }

        // Properties
        public string CarMakeID
        {
            get { return (carMakeID ?? string.Empty); }
            set
            {
                Assert.ArgumentNotNull(value, "carMakeID");
                carMakeID = value;
            }
        }

        protected override bool Execute(T ruleContext)
        {
            try
            {
                Assert.ArgumentNotNull(ruleContext, "ruleContext");

                // Logic goes here
    // carMakeID is the item ID for the selection
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
When the content editor uses the rule, Instead of typing the value in, a box will popup to make the selection.