1

How can I trigger Update Commerce Data Templates from SPE? I am automating a Docker deployment script and the one step that I am missing for it to be fully automated is being able to do this from powershell Sitecore version is 9.2 if it matters

0

Sitecore Commerce 9 uses custom .aspx page to generate data templates during installation process.

You can find this page here: SIF.Sitecore.Commerce.*\SiteUtilityPages\GenerateCatalogTemplates.aspx

The code of this page looks like below:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="log4net" %>
<%@ Import Namespace="Sitecore.Data.Engines" %>
<%@ Import Namespace="Sitecore.Data.Proxies" %>
<%@ Import Namespace="Sitecore.SecurityModel" %>
<%@ Import Namespace="Sitecore.Update" %>
<%@ Import Namespace="Sitecore.Update.Installer" %>
<%@ Import Namespace="Sitecore.Update.Installer.Exceptions" %>
<%@ Import Namespace="Sitecore.Data.Managers" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Publishing" %>
<%@ Import Namespace="Sitecore.Commerce.Engine.Connect.DataProvider.Templates" %>

<%@ Language=C# %>
<HTML>
    <script runat="server" language="C#">
        public void Page_Load(object sender, EventArgs e)
        {
            Response.Write("Catalog template generation started: " + DateTime.Now.ToString("t") + "<br>");

            Sitecore.Context.SetActiveSite("shell");
            using (new SecurityDisabler())
            {
                DateTime publishDate = DateTime.Now;
                Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
                var templateGenerator = new CatalogTemplateGenerator();
                templateGenerator.BuildCatalogTemplates(master);
            }

            Response.Write("Catalog template generation completed: " + DateTime.Now.ToString("t") + "<br>");
        }

        protected String GetTime()
        {
            return DateTime.Now.ToString("t");
        }
    </script>
    <body>
        <form id="MyForm" runat="server">
            <div>Catalog templates generated.</div>
            Current server time is <% =GetTime()%>
        </form>
    </body>
</HTML>

This is what you can use OOTB.

In your case, you can invoke C# method from your PowerShell script, if you want.

1
  • This worked like a charm, thanks!
    – Nikola R
    Dec 22 '20 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.