Creating a Sitecore Experience Commerce catalog programmatically
Initializing your catalog in code is a great way to ensure that all developers can access the same data when they are working with the Sitecore Commerce Engine. You could of course do a catalog export and import it from a file, but the advantage here when combined with generated categories and sellable items is that custom components can be added, removed and updated and the catalog data will reflect those changes without needing to make manual changes.
First, we need the pipeline that will create a new empty catalog.
InitializeCatalogBlog.cs
Next, we need to wire that up so that the commerce engine will register it in the pipelines.
ConfigureSitecore.cs
Make sure you add a reference to MyProject in your Sitecore.Commerce.Engine project. Then when you build (and deploy), your catalog initialization above will be ready to go.
Once you’ve got the engine running, open Postman and in the postman scripts that come with the SDK, you’ll want to run CleanEnvironment() to remove any existing catalogs and entities,
and then run InitializeEnvironment() to set up your new catalog. You can use the Check Long Running Task request to verify when initialization has been completed and to see if there are any errors. Also check for any errors in the engine logs.
Thanks to Andrew Sutherland from Sitecore for help in getting the right pipelines and other things in order.