However, with this great flexibility the issue arises on how to move the metadata (composer templates) between environments. For instance, how do I ensure all my developer machines have the same templates and the correct version of those templates. There is also the issue of moving new entity fields to Test and Production environments.

The other way to do this will be to serialize the composer templates to JSON and bring them in again in the destination environment. Detailed here is my preferred approach for projects where you have templates that will change often (in Agile projects this is common of course) , many templates and many developers i.e. a large complex project.

The code first approach to composer template deployment outlined here, follows the premise that templates are created and managed in code. Therefore they can be version controlled and history can be tracked in Git or elsewhere along with all your other code.

Developer flow :-

  1. Developer A writes the code to create the composer template.
  2. The engine code is checked in by Developer A
  3. Developer B gets the latest code.
  4. Developer B runs the API command in the engine via postman manually to create the composer templates in his environment. This could also be automated.
  5. Developer B runs “update templates” function in Sitecore.

Deploy to Test or Prod flow :-

  1. Developers create and update composer templates via code in the commerce engine
  2. End of sprint build is created
  3. Commerce engine build is deployed to environment
  4. The API command in the engine is run manually or through automated mechanism to create composer template
  5. “Update templates” function is run in Sitecore. (Can be automated)

The following code is a commerce engine plugin that can be used as a template…well to create your templates 🙂

It is made up of the following components :-

  1. New pipeline and pipeline block, the code responsible for creating the templates via code.
  2. New API command, this command exposes the create composer templates via the engine so it can be called manually or through an automated build process.

Step 1 – Create new plugin

The command in this plugin, when run, will create a new template called “DiscontinuedTemplate” with one boolean field called “Discontinued”. The new template will be assigned to all “Refridgerator” sellable items (Product definition)

  • In the Commerce Engine SDK create a new plugin and reference it from the engine
  • Add the following code to create the pipelines

In folder “Pipelines” create…

In folder “Pipelines\Arguments” create…

In folder named “Pipelines\Blocks” create…

  • Add the following code to be able to execute the code externally via the API

In folder “Commands”…

In folder “Controllers”…

  • Add the following to tell the engine about your new commands and pipelines

In the root of your project add…

Your solutions should look like this…

composer templates

Step 2 – Run

  1. Go to Postman and run https://{{ServiceHost}}/{{ShopsApi}}/CreateComposerTemplatesCommand
  2. Go to the business tools and ensure that your template is created.
  3. Go to a sellable item and set the discontinued flag to true.
  4. Go to Sitecore and on commerce tab, hit the update templates button
  5. Open the item from step 3 in the content editor, you should see the discontinued field checked.