Sitecore Experience Commerce – XC9 – First Look and Feel

Sitecore released their much awaited module – Sitecore Experience Commerce (or XC9 in short) in late January 2018. As an avid Sitecore enthusiast, I was eager to learn more about it. On a free weekend, I decided to install and play with it. This blog is about the first look and feel about the XC9 module and only explores very high level features. The detailed documentation about the module can be found at the official site.

The Storefront

Once the installation is complete, the modules comes with an sample store called the Storefront.

The home page comes with featured carousel and product list components (SXA based)

Clicking on any of the top menu items (for example Appliances) will present the list of products with filtering and sorting options:

Clicking on an individual item will take the user through to the product details page, where the user can add the product in their shopping cart:

The Checkout Process

The checkout process is very user friendly and can be compared with any top of the line commerce stores. For example if the user decides to add a laptop and click on the ‘View Cart‘ link from the top right, the user will be shown the summary of cart:

The user can either click ‘checkout‘ or click ‘continue shopping great products‘. If the user decides to click the ‘checkout‘ button, the next screen asks for delivery details to calculate additional shipping charges:

The user can check ‘Ground’ option and click ‘Continue to billing’. The next screen asks for ‘Billing’ details and also includes shipping charges:

Before the user can continue,  the user must validate credit card details. At the moment, the system is configured to use Braintree sandbox account. The user can enter any of the test credit card details available from the Braintree website and click ‘Validate Payment’:

Once the credit card has been validated, the user can proceed to the final review screen before hitting ‘Confirm Order‘ button:

The final screen will show order confirmation number:

That was an amazing experience for buying a product and as a user, I am very much impressed!

The Business Tools

So that was the customer experience, now lets see what is there in the for the back office administrators. After installing the XC9 module a new icon as ‘Business Tools’ should be available for admin users from the Sitecore Experience Platform dashboard.

The Business Tool dashboard comes with 7 sub-modules to manage the store.

  • Merchandising
  • Inventory
  • Pricing
  • Promotions
  • Orders
  • Customers
  • Relationship Definitions

Since the user has just made a purchased, lets checkout what is in the ‘Order’ module

Clicking on the ‘Order’ link from the dashboard or side link, the admin user can see one order is in the ‘Pending’ state:

Clicking on the pending order link, the admin user can see the details about the order:

This out of the box back office processing system for admin users looks amazing as they can instantly see all the order summaries and details. I will pause the exploring rest of the commerce modules as they require much more detail and perhaps another blog.

The Storefront Content Tree

The Storefront content tree is based upon conventions and structure introduced by SXA module. The SXA modules comes with 80+ components for speeding up the development process.

A new set of commerce components are added in the SXA toolbox library.

All of the pages in the Storefront are developed using SXA or Commerce-SXA components.


As you can see, Sitecore Experience Commerce 9 is a very rich and extensive module for developing an online store. In this blog, I have only scratched the surface of the module and I am super excited about it. The 40+ commerce SXA components, the 7 back office processing modules, and additional 80+ standard SXA components for rapid website development, all together deliver a knockout punch in the online commerce industry

In my opinion, Sitecore XC9 module will definitely meet the expectations of any business looking for a modern, cloud-ready and secure online store. So, if you manage an online store and looking for replacement options, do evaluate  Sitecore Experience Commerce out before making any decisions.




SXA Rendering Variants – The Hidden Gem of Sitecore Experience Accelerator (SXA)

Sitecore Experience Accelerator  (SXA) is a great productivity tool as it reduces your development time by giving you pre-built components. There were few new concepts and features that were also introduced with SXA like Page design and Partial design, pluggable themes, grid and column layout etc, but as the topic suggest, I will be focusing upon “Rendering Variant” concept and will try to explain how can this change the way you architect your website (assuming that is based on SXA).

Problem Statement

Let’s begin with a problem statement, the UX team have prepared a landing page and they have the various content components on the page displaying Image, Rich Text and Link all in a box but in various styles as below:

  1. Half-width component with Image and Text
  2. Half-width component with Image, Text and Link
  3. Full-width component with Image on Left, Text and Link on Right
  4. Full-width component with Image on Right, Text and Link on Left

They also want the content authors to have the ability to add them, remove them and order them in any way they like.

Sounds familiar ?

If I am not using SXA module, one of the approach would be to make these different components available via Experience Editor which content editor can add/remove/order from the content page. This means that there will be different “View Renderings” for each of the components types. Different view rendering mean different Data Source Templates and Data Folder Templates. So for the simple content based components above, we end up having 4 different view renderings, which more or less have same content but it is displayed differently.

SXA Approach


There is nothing wrong with the above approach, but if you website is based on SXA module you would have another tool to  meet your goal in a more effective manner.

The SXA provides a feature called Rendering Variant which optimizes the process of showing different variations of the same component. The variations can be setup via content editor and can also be supplemented with predefined styles and scripts.

The best way to explain Rendering Variants is by an example. I will be using the out of the box “Promo” component that comes with SXA. I am only interested in 3 data fields PromoText, PromoIcon and PromoLink (there are other properties too, but let’s keep it simple)

Promo Data Template

Rendering Variants are located under the /Site/Presentation/Rendering Variants node. In my case, the location was:

/sitecore/content/Tenant Folder/Tenant 1/Site 1/Presentation/Rendering Variants/Promo

Out of the box there was one rendering variant already present as ‘Default’.

Default rendering variant

I made a copy of that component and called it ‘Promo with Image and Text’

Promo with Image and Text rendering variant definition

I then deleted last child item ‘Promo Link’ from the recently created rendering variant and clicked save. The ‘Default’ rendering variant was renamed to  ‘Promo with Image Text and Link’ for readability purposes. And just by doing these few content item operations, I was able to achieve my 2 component variations (under like 1 minute, thanks to SXA)

To verify my changes I tested them out in experience editor. First I added a column splitter component to divide the page into 2 equal halves, then I  uploaded some stock images, added the Promo component from the Toolbox in each of the half , added random text and selected my variants via the dropdown. They worked like a charm!

Promo with Image and Text, Promo with Image, Text and Link

Similarly, I created a copy of the existing variants and called it “Promo with Image left” . I then added a ‘Section’ item for the variant definition and called it ‘Container’. I then moved “Promo Icon” under it. I also added the bootstrap class of ‘col-xs-6’ to ‘Container’ item and to the ‘Promo Text’ item.

Section item surrounding PromoIcon field in rendering variant definition

As you can see in the screen shot above, there are other types of variant definition items as well, check them out from the official site and see how flexible they are to give you almost any kind of rendering variation that you like.

For “Promo with Image Right” I created a copy of the “Promo with Image Left” and just reversed the order ‘Promo Text’ and ‘Container’ sections:

Image Left and Image Right rendering variant definitions

To verify my changes, I navigated to the Experience Editor, dropped the ‘Promo’ component on the page and changed its rendering variant via the dropdown to get the results below:

Promo component with Image Left

Promo component with Image Right

And that’s it, without even writing a single line of code, I was able to get all 4 component variations. In theory the number of variations that could be achieved using rendering variants are unlimited and totally depend upon your UX and Design.


If you are starting a new website based upon SXA module, you must consider rendering variants for your components as it will change the way you architect the website. This was a simple post but it showed the true power of SXA and how Rendering Variants can reduce back-end development efforts and also improve the content authoring experience. Kudos to SXA development team for this awesome feature!

Have fun

Note: If you want to play around with the, here is the link to the rendering variant package. I have used Sitecore 8.2 update 5 and SXA 1.5.

Sitecore DevOp Series – Part 2 – Setup and Configure Visual Studio Sitecore Project

This is the second part of the Sitecore DevOp Series. In this blog post, we will setup a Visual Studio project for a brand new Sitecore, create a local publish profile and add XML config transforms. The blog series is aimed at newer audience and developers who are setting up CI for the first time.

Step 1 : Create Visual Studios Project

At the time of writing this blog post, I have used VS 2015. Open Visual Studio, navigate to File > New > Project and within templates select Templates > Visual C# > Web > ASP.NET Web Application project. Make sure the .NET Framework is set to 4.5.2 or above. Optionally you can un-tick the ‘Application Insights’ box if you are not using it:


The VS project physical location should be setup somewhere other than the installed instance of Sitecore. For the purpose of the blog, it will be at C:\projects\MyProject where as the installed Sitecore instance will be at C:\inetpub\wwwroot\myproject\website. If you are not sure which version of .NET to use with your Sitecore instance, please check out the compatibility matrix.

Step 2 : VS Project Type

Select ‘Empty’ template project but tick the ‘MVC’ box under the core references. If you are not using Azure, un-tick host in the cloud option as shown below:


Step 3 : Exclude and Delete Files

Once the project is created by the wizard, it will also installed some standard configuration files which we will overwrite in the next step. For now, please exclude the following files from the project and also delete their physical version:

  1. Global.asax
  2. Global.asax.cs
  3. Web.Config
  4. Web.Config.Debug
  5. Web.Config.Release


Step 4 : Copy and Include Files

Navigate to the installed directory that was created automatically by the Sitecore Installer. In this case it will be C:\inetpub\wwwroot\MyProject\Website and copy the following files into current project:

  1. Default.aspx
  2. Default.css
  3. Default.js
  4. Global.asax
  5. Web.config
  6. Webedit.css

Include these files via the VS project ‘Include File’ options

Step 5 : Add Sitecore References

Navigate to the bin folder of the installed directory that was created automatically by the Sitecore Installer. In this case it will be C:\inetpub\wwwroot\MyProject\Website\bin and copy the following files in a folder called ‘references’ (or lib or another folder of your choice)

  1. Sitecore.Kernel
  2. Sitecore.Client
  3. Sitecore.Logging
  4. Sitecore.Mvc
  5. Sitecore.NVelocity
  6. Sitecore.Updated
  7. Sitecore.Zip
  8. Sitecore.Analytics


Reference these files via the VS project’s  ‘Add Reference’ option

Recently, Sitecore has also released NuGet feed for distribution purposes, you may use that as well as per their documentation.

Step 6 : VS Custom Projects

Sitecore has recently released and recommended Helix Framework for overall design of Sitecore projects. It is strongly recommended for any future projects to be based around these design principles. However, for simplicity purposes and keeping in mind the target audience, we can just add the following class library projects:

  1. MyProject.Domain (It can contain auto-generated data model for the templates and other models)
  2. MyProject.Sc (It can contain Sitecore specific customization code like workflow, pipelines etc)


Once both projects are added, the overall VS project should look like below:


Step 7 : Setup Local publish profile

The next step will be to setup a local publish profile for the project, as the installed directory location was different then the VS project location.

Create a new custom publish profile as ‘local’ from the ribbon option



Select ‘File System‘ for the publish method drop-down and select the target location of the installed directory as shown below:


Select ‘Debug‘ option from the configurations drop-down so you can debug the code locally after deployments. This should only be chosen for local deployments, for QA and other environments, ‘Release‘ should be selected.


Preview all your settings and hit publish, upon successful publish you should see the following message:


Step 8 : XML config transforms

We need to create environment specific config files which we can then transform to correct config settings during the automated deployment.

For this purpose, install VS SlowCheetah extensions and then you right-click to add any new configuration files. For example, after I right-click on the Sitecore.config I see the following options:


Once you click ‘Add Transform’ new config file (Sitecore.local.config) will be added in the project. This is where environment specific settings can be updated and upon publish they will be transformed. This alone will save you a lot of time of managing different config settings for different environments.



A sample XML transform file for replacing the dataFolder location could be:

<?xml version="1.0" encoding="utf-8" ?>
   <sitecore xmlns:xdt="">
       <sc.variable name="dataFolder" value="C:\Inetpub\wwwroot\myproject\Data\" xdt:Transform="Replace" xdt:Locator="Match(name)"/>

Although, you don’t need to specify this variable for local deployment, but you will when it comes to QA, UAT and production deployments. You may want to repeat the same process for connectionstrings.config file.

More information about XML transformation can be found on MSDN website

Once the initial setup project is done, we are ready to add configure TDS projects which will be discussed in the next post.

Stay tuned.


Related Blogs

  1. Part 1 – Continuous Integration – Why your Sitecore project deployments must be automated ?
  2. Part 2 – Setup and Configure Visual Studio Sitecore Project
  3. Part 3 – Setup and Configure TDS
  4. Part 4 – Setup Sitecore Glass
  5. Part 5 – Setup Source Control (Git)
  6. Part 6 – Setup QA Server, DB server and CI server
  7. Part 7 – Setup Continuous Integration using Team City
  8. Part 8 – Setup Slack Notifications with TeamCity and Bitbucket

C# – Limit Paragraph Length using Simple Extension Method

Happy New Year 2016 !

In most of the web applications, you will encounter a scenario where you have to display the summary of the page in limited amount of space. For example, on a section level page, sometimes you are required to display sub section summary information but due to design constraints, you can only display 80 characters.

The .NET framework provides .Substring() method to limit the string length and generate a new sub-string but this method is not clever enough to distinguish between words and empty spaces in a long paragraph and can result in a sub-string where a word has been truncated in the middle of being displayed, giving bad output to the end user.  How can we solve this ?

Here is a simple string extension method that will nicely truncate the paragraph and it will also add “…” at the end of the returned string value.

Step 1 : Add this extension method class in your project

namespace StringExtensions.LimitSentenceLength
    public static class StringExtensions
        public static string LimitSentenceLength(this string paragraph, int maximumLenght)
            //null check
            if (paragraph == null) return null;

            //less than maximum length, return as it is
            if (paragraph.Length <= maximumLenght) return paragraph; 
            //split the paragraph into indvidual words 
            string[] words = paragraph.Split(' '); 
            //initialize return variable 
            string paragraphToReturn = string.Empty; 
            //construct the return word 
            foreach (string word in words) 
            //check if adding 3 to current length and next word is more than maximum length. 
            if ((paragraphToReturn.Length + word.Length + 3) > maximumLenght)
              //append "..."
              paragraphToReturn = paragraphToReturn.Trim() + "...";
              //exit foreach loop
             //add next word and continue
             paragraphToReturn += word + " ";
           return paragraphToReturn;

Step 2 : From your main application, you can call this method as following :

using System;

namespace StringExtensions.LimitSentenceLength
    class Program
        private static string Paragraph => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

        static void Main(string[] args)
            //Lorem ipsum dolor sit amet, consectetur...
            //Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
            //Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam,...
            //Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut...

How simple is that !!!

Sample code is available on GitHub

C# – Random ordering of IEnumerable using Extensions

This is just a quick post about random ordering of IEnumerable types using C# extension. For example you have a IEnumerable of type ‘Employee’ object and you want to randomly pick 7 employee objects, how would you do that? This blog post will create a simple extension method for IEnumerable and show how to use it.

Step 1 : Create an extension class for IEnumerable as below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sample
    public static class EnumerableExtentions
       public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source)
            var range= new Random();
            return source.Randomize(range);

        private static IEnumerable<T> Randomize<T>(this IEnumerable<T> source, Random range)
            if (source == null) throw new ArgumentNullException("source");
            if (range== null) throw new ArgumentNullException("range");

            return source.RandomizeAlgorithm(range);

        private static IEnumerable<T> RandomizeAlgorithm<T>(this IEnumerable<T> source, Random range)
            var temp = source.ToList();

            for (int i = 0; i < temp.Count; i++)
                int j = range.Next(i, temp.Count);
                yield return temp[j];

                temp[j] = temp[i];

Step 2 : Use it within your main code as below :

           //get all employees
            var employees = Employee.GetAllEmployee();
            //print in sequence
            //randomize using extension
            var randomEmployees = Employee.GetAllEmployee().Randomize();
            //print them again

Job Done!

Sample code is available on GitHub

Note : I am using Fisher–Yates shuffle  algorithm for randomizing the collection.

Getting started with MongoDB 3.0 using some new features of C# 6.0

Recently, I had to work on an application which used MongoDB as a back-end database. As it was my first MongoDB based project using C#, I went through a learning curve and thought it will be a good idea to do a step-by-step guide. So, if you are new to MongoDB, here is a quick post to get you up and running

Step 1: Download and install VS 2015 Community edition, it’s free for personal use with registered email address!


Step 2: Download MongoDB and install it on your local machine.


Step 2.1 Create a data directory or empty folder at C:\data\db (this is the default location for MongoDB to store files, but can be changed)

Step 2.2 Open CMD with administrative privileges and navigate to MongoDB install folder and start mongod.exe program. In my case the path was C:\program files\mongodb\server\3.0\bin and then the command mongod.exe


Step 3: Download RoboMongo which is an open-source GUI for MongoDB management.


Step 3.1 Assuming MongoDB is up and running, create a new “localhost” connection and test it.

Step 3.2 Click on View > Explorer and you will see list of localhost DBs.


Step 4: Open VS 2015 and create a new Console Application (for production purposes, you might need a class library, but for demo I am using console application)


Step 5: Right click on References > NuGet Packages and install ‘Official .NET Driver for MongoDB’


Step 6: Create your collection class, for purpose of this blog, I have created a Customer class.

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System;

namespace MongoDBTestApp
    public class Customer
        //required field to perform read/write opertions on Bson or Binary Json
        public ObjectId Id { get; set; }

        //C# 6.0 property initializers
        public string FirstName { get; set; } = "John";
        public string LastName { get; set; } = "Doe";
        public DateTime Timestamp  { get; set; } = DateTime.UtcNow;

Step 7:  Insert objects as collection in Mongo DB

using MongoDB.Driver;
using System.Threading.Tasks;

namespace MongoDBTestApp
    class Program
        static void Main(string[] args)
            //creates a MongoDB client from conn string
            var client = new MongoClient("mongodb://localhost");
            //gets the database within client, if it doesn't exists, creates it
            var database = client.GetDatabase("customer");
            //gets the collection from the database,if it doesn't exists, creates it
            var collection = database.GetCollection("customers");
            //insert into database

        static async Task InsertCustomer(IMongoCollection collection)
            await collection.InsertOneAsync(new Customer());


Step 8: Find your object from Mongo DB and display it

 static async Task FindCustomer(IMongoCollection collection)
            //creates a filter to find Bson Document
            var filter = Builders.Filter.Eq(c => c.FirstName, "John");
            //runs the query to find it
            var query = await collection.Find(filter).ToListAsync();
            //gets the customer
            var customer = query.FirstOrDefault();
            //displays the customer using new C#6 string formatters
            Console.WriteLine($"Customer {customer.FirstName} {customer.LastName} is found!");



What you have now is a fully functional MongoDB application where you can store records and retrieve records, how easy was that!

All code is available from GitHub.



C# – Read/Write CSV files using FileHelpers

This is 2015, and we shouldn’t be working with CSV files any more, but reality is, they are the most commonly used file exchange method around.

As a C# developer, we can make use of standard String and Array classes and we can read/write CSV files. However, there is a maintenance issue, imagine you have a CSV file with 15+ columns, and now you have been asked to update the code with additional columns.  Updating index based columns with additional column is a tedious and error prone task.

There is a better way, use FileHelpers. This is a free and Open Source C# library to handle CSV files related operations.

This can be installed as NuGet package within the project.

I am going to assume that the CSV file has got only 2 columns as following :



And the description column could have double quotes ” and a comma can be included within the double quotes.

Step 1 : Create a simple C# class for the CSV file and add field attributes using FileHelpers as following:

Step 2 : The Second step would be to read the flat CSV file into this object.

And that’s it. In case you have to add more columns or remove any column, all you have to is to update the ‘MyProduct.cs’ class file and update the associated strongly typed code.

Now lets assume the opposite, that you have a some sort of data in the database or CMS or external data source and you want to write that into CSV file.

Using the same ‘MyProduct.cs’ class above, the write method will be as following:

Whoooa! that’s it.