Commerce Server – Missing ProductId in Product Definition

For one of my Sitecore projects using Commerce Server I wanted to add a new Product Definition (to see how that’s done, go to my previous blogpost on just that subject).

So after I created a new Product Definition and had the definition to my specifications I updated my data templates in Sitecore and started working on some products and product pages. To work on products I’d use the SPEAK application Merchandising Manager (can be downloaded here for Sitecore 7.5 or here for Sitecore 7.2), which is where I ran into an issue. Opening a product based on my new product definition an exception was thrown. The error is ‘Sequence contains no matching element’, with the stacktrace showing that a renderer was trying to get a field called ‘ProductId’. Looking at my definition, the ProductId property was indeed missing – and what’s more, it wasn’t possible to add it either as displayed in the screenshow below.

The New Definition window

There is an extremely simple workaround for this: in Sitecore, we can go to our data templates, by default located in /sitecore/templates/Commerce/Catalog Generated. Find the template generated for the product (or category) definition, in our case the MyDefinition template, and add a Single-Line Text field called ProductId.

Added ProductId field

Save that and that’ll take care of the issue. One thing left though. If we were to browse to the Merchandising Manager and open our product now it would load up, but the ProductId would still be blank and there would be an error on the top of the page because of this. Of course, we could go ahead and fill in the ProductId and save it, or we could open the Content Editor, browse to our product and hit Save. This will automatically set the ProductId field we created and will fix the general error we were having. Of course, if you have a lot of products, you might consider creating a script to do set the ProductId for you.

Sitecore Commerce Server – Products and Definitions

I’ve been working with Commerce Server now for a while, trying to enable it on our dev environment. After the installation process (which might require its own post as well), I figured I’d write something about how to get product definitions, products, category definitions and categories from Commerce Server into Sitecore.

Creating definitions

The Product Definitions and Category Definitions (and I’m guessing Property Definitions also, but I haven’t used custom properties yet) work in a similar way. They can be created in the Commerce Server Catalog and Inventory Schema Manager, using the appropriate view in the Views panel on the bottom left in the screenshot below.


Creating a new definition is reasonably straightforward. Just give the definition a name and optionally a description, and select the properties you’d like that particular definition to use. After this, you’re done! You can now create new products or categories based on that new definition.

Creating products and categories

Creating new categories and products can be done in the Commerce Server Catalog Manager. Right-click where you’d like to add a new category or product, and use the context menu to create a new category or product. Alternatively, you could use the SPEAK app Merchandising Manager, on which I’m sure more blog posts will be coming as well. In the meantime, more on the Merchandising Manager can be found here. When using the Merchandising Manager, you can skip to the section about getting the definitions to Sitecore. When using the Commerce Server Catalog Manager, you can follow the steps below to get create products or categories.


In this screenshot you can see I’m using the MVC demo store (of which you can download the source on the Sitecore Marketplace or the Sitecore package from SDN if you don’t need the source).

Creating a new category and/ or new product will pop up with a wizard which will run through the various steps (Selecting the definition, entering the properties followed by the custom properties, selecting primary and additional categories and then selecting relations for the category or product). This is all very easy to do.

All done, we have our products and categories in Commerce Server.
Now, how do we get this to go into Sitecore? If the product and category definitions already exist in Sitecore,  products and categories will be synced automatically, although caching might get in your way sometimes.

Syncing products and categories

If they don’t get synced automatically, and the definitions exist, there’s two options:

  1. In the Commerce Server Catalog Manager, in the Tasks pane, click ‘Refresh Site Cache’.
  1. After logging into Sitecore, you can go to the Content Editor, go to the Sitecore Commerce tab in the ribbon, and click ‘Refresh Sitecore Cache’.

Syncing definitions

To make sure your definitions go into SItecore (they will be used as the data templates), you need to go into the Content Editor and click ‘Update Data Templates’ in the Sitecore Commerce tab in the ribbon.

Don’t forget to publish – in fact, when there’s new definitions and new products/ categories I’ve had to to a full republish in some cases- and don’t forget to re-index as well.