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.
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.
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.