Sitecore E-Commerce Services Part 1 - Setting Up Products

Thursday, November 14, 2013 @ 04:28

Sitecore E-Commerce Services Part 1 – Setting Up Products
By: Dusty Eves, Senior Developer

Introduction

From a technical perspective, e-commerce and content management are very similar problems.  At its core the task of creating pages for on-line products and organizing it into useful groupings, making sure your user can find it is ultimately a content management task, albeit with a very specific kind of content.  CMS to e-commerce is a small jump, one Sitecore answers with Sitecore E-Commerce Services.  Particularly if you're new to either Sitecore or Ecommerce it can be a bit daunting at first glance.  So I'm here to take you through the steps from installation to fully functioning Sitecore Ecommerce site.  For the purposes of this tutorial we're going to use the latest and greatest of Sitecore (at least at the time of this post) Sitecore 7 and Sitecore E-Commerce Services 2.1 rev 130718.

Installation

There are three aspects of Sitecore E-Commerce Services, SES Core and the Order Manager, and the Sitecore E-Commerce Example.  Right now we're just focusing on SES Core, the Order Manager will be address in a later tutorial. 

This tutorial also assumes that you have a clean install of Sitecore 7.  The full installation guide for SES can be found here, but the steps are pretty straight-forward.  
•    Download the package from here and install.  
•    During the installation, the installer will drop two sets of SQL Database files in your Sitecore App_Data directory: SitecoreEcommerce_Orders and Sitecore_Ecommerce_ActionLog.  Move said files to your database directory and attach them to SQL.
•    Create two new entries in your Sitecore connection strings file.  One named “orders” and one named “logging” pointing to the two databases attached in the previous step.  Additionally, make sure both connection string entries have the additional property “MultipleActiveResultSets=true”.

Initial Setup

At this point if you go into the Sitecore content editor and navigate to /sitecore/System/Modules you should see an E-Commerce node.
There's a lot to the SES Module and it's components have a lot of inter dependencies.  The easiest way set the scaffolding for your initial store is to copy the Modules/E-Commerce node to /sitecore/Content/ and rename it.  From your new E-Commerce node go into Webshop Site Settings.  You'll find a number of links still pointing to E-Commerce node in Modules that you'll need to point to the analogous setting under your new site node.  Go ahead and delete the Catalogs and the System node, as they're not needed here.

Once you have your webshop node setup, next step is to setup your E-Commerce store context.  In the sites node of your web.config file, add to your website node three new properties:  EcommerceSiteSettings=”/Webshop Site Settings”.  Note that this path is relative to the startItem of your site.  Also add, ordersDatabase=”order” and actionLogDatabase=”logging”.  Also make sure the sites content property is set (i.e. content=”master”)  These are analogous to the additional connection strings added to the config file.

 


The final step of the initial setup is to setup the product index.  In the Include config folder the package will have added a Sitecore.Ecommerce.Config file.  If you navigate to search/indexes you will find a product index with a section commented out.  To enabled the product index, uncomment the section and replace the value for the Root node with the ID of the Product Repositories node in the E-Commerce site section that you created.  The end result should be much like this:



At this point if you've lined up all the necessary ducks you're ready to start create your products.  To test the initial setup in the content editor select the Product Repositories node.  If the Product Catalog loads then so far so good.  

Product Repositories
Products in SES are stored in product repositories.  The proper structure for a repository is:
•    Repositories Group
◦    Repository 1...n
▪    Category 1...n
•    Product 1...n

A repository in this context is a container to store products organized for ideal management.  Unlike much of Sitecore content, the way products are organized in the repository has no need to correspond to the structure of your site.

In addition to the folder structure SES has an additional field to organize the repository: Brand.  There are a few facets missing to make use of brand.   First step create a folder called Brands underneath your Product Repositories folder.  As of SES 2.1 130718, there is no existing Brands so we'll have to create our own.  Create a brand template and give it at a minimum a field of Title.  Then navigate to Modules/E-Commerce/Catalogs/Product Catalog/Checklists/Brands and set the root to the Brands folder you created.  Once done your brands folder will be a filtering option on the Product Catalog screen.



Product Grouping Pages
We've previously asserted that the structure of products in the product repository doesn't relate to how the products exist in the site structure.  In SES the presentation structure is disconnected from the hierarchy of our Sitecore tree.  This is important for use cases where there are multiple vectors by which one can organize products.  For example, a book publisher might want to present books by Genre as well as Author.  This is where Product Search comes in. 

Product Search Groups are the vehicle by which products are displayed in SES.  Don't get too hung up on the “search” aspect of the name, search groups support both static and dynamic implementations.  So our first step, add an instance of the Product Search Group Folder template to your site node (/sitecore/templates/Ecommerce/Product Categories/Product Search Group Folder).  This is the jumping off point for how your products appear in your site.  There are some settings here we'll revisit in a moment.  Next step as add an instance of the Product Group  template to your search group folder.  Clicking on this item will bring up a Product Page by which you can select the products that will appear on this page (for more on rendering product group pages see {here}). 

ProductResolver
Now that we have our grouping pages our next step to figure out, how to actually get to the products.  In SES products, unlike most Sitecore content, isn't accessed with a URI that corresponds to its path in the tree.  This is where the ProductResolver comes in.  If you select your Product Search Group Folder you'll not at the bottom a dropdown “Display Products Mode”.  Select “Resolve Products by Item Name” and save.  This sets the resolution method and now products can be resolved with any valid URI below the Product Search Group Folder that ends in the products name.


Product Presentation
If you're following the steps in the tutorial there's a good chance that if you go right now to the analogous url for your site you'll get a Null Reference Exception from the ProductResolver.Process method.  The reason for this exception is that unlike most Sitecore items, the presentation definition isn't tied to the actual product item.  On your Product Search Group and your Product Search items you'll note  towards the bottom the setting “Product Detail Presentation Storage”.  This field points to the folder /Modules/E-Commerce/System/Product Presentation Repository/ and its the item selected in this field that defines the presentation of the product (adding presentation details to the “Product Details” item will resolve this error).  While this does depart from Sitecore's normal method of presentation definition it has the advantage that presentation can be defined in a way that is context sensitive.