Search code examples
sitecoreumbracositemapumbraco-ucommerce

How to generate a uCommerce Sitemap XML


I am trying to find the simplest way to generate a sitemap XML for a uCommerce site. I am using it with Sitecore, but I think any solution that works for Umbraco could also be useful as a start.

My last resort is to crawl the site (or use a tool to do so) but I would like to be able to do trigger it programatically (our products are updated by a remote feed, so I cannot hook into any save pipelines to update the sitemap) and do it without crawling the site every time we update a product.

I can find numerous Sitemap generators for Sitecore, but the uCommerce products sit outside of the main content tree so they do not include the uCommerce products and categories in the sitemap.

Is there a simple way to generate a uCommerce sitemap without custom code/using a crawler?


Solution

  • As Zachary mentions in the comment you should be able to hook into the item:saved or item:saved:remote pipeline.

    If that's not the case, you could also consider creating an agent, which you can create in the scheduling node of the web.config (or create an .config for your solution in the Include folder as is best practice of course).

    You can add an agent:

    <agent type="Your.Agent" method="Run" interval="00:10:00">
        <param desc="yourparameter">parametervalue</param>
    </agent>
    

    This means that your Your.Agent class should have a method Run, which will be called every 10 minutes in this case - of course that's dependant on the frequency setting in the same scheduling node as well. Frequency defines how often Sitecore needs to check whether agents need to run, interval defines how much time between each run of the agent needs to be passed. More on Sitecore agents here. The link mentions scheduled tasks as well, which you should also be able to use. This only works if there's a defined time period in which you would like to update the sitemap rather than every time a product is updated (for example, it could run every hour)
    You can then also add parameters with a specific value (i.e. the location of the store you want to include in your sitemap or templates you want to exclude etc.).

    You should then be able to hook into the Sitemap.xml file and append it with your uCommerce products and links using something like CatalogLibrary.GetNiceUrlForProduct(productToRender)