+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Sitemap

Custom Sitemap

4 posts, 1 answered
  1. Jason Chester
    Jason Chester avatar
    11 posts
    Registered:
    03 Feb 2010
    04 Oct 2011
    Link to this post
    I am developing a custom sitemap which integrates products from my custom product module in to the site map. I am seeing some strange behavior in the Custom sitemap where products only appear some of the time. I think it may be something to do with caching of the sitemap nodes but I am just not sure.

    I developed the custom sitemap by inheriting from PageSiteNode as follows.
    using System;
    using Dannon.Sitefinity.ProductModule.Model;
    using Telerik.Sitefinity.Data;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Web;
     
    namespace Dannon.Sitefinity.Web.UI
    {
        public class ProductSiteNode : PageSiteNode, ISitefinitySiteMapNode
        {
            public string ProductProviderName { get; private set; }
     
            public ProductItem Product { get; private set; }
     
            public override string Url
            {
                get
                {
                    return "~/products/details/" + this.Product.UrlName;
                }
                set
                {
                    throw new NotSupportedException();
                }
            }
     
            public override string Title
            {
                get
                {
                    return Product.NavigationTitle;
                }
                set
                {
                    throw new NotSupportedException();
                }
            }
     
            public ProductSiteNode(SiteMapBase provider, PageNode pageNode, string pageProviderName, ProductItem product, string productProviderName)
                : base(provider, pageNode, pageProviderName)
            {
                this.CacheDependency = new CompoundCacheDependency();
                this.CacheDependency.CacheDependencies.Add(new DataItemCacheDependency(product.GetType(), product.Id));
     
                if (provider == null)
                {
                    throw new ArgumentNullException("provider");
                }
                this.ProductProviderName = productProviderName;
                Product = product;
            }
        }
    }

    I then overrode GetChildNodes in my custom sitemap provider inherited from SitefinitySiteMap.
    public override SiteMapNodeCollection GetChildNodes(SiteMapNode parent, bool ifAccessible)
    {
        var taxMan = GetTaxonomyManager();
        var departments = taxMan.GetTaxonomy(ProductsModule.DepartmentTaxonomyId).Taxa;
        SiteMapNodeCollection childNodes = base.GetChildNodes(parent, ifAccessible);
      
        var department = departments.FirstOrDefault(d => parent.Url.EndsWith(d.UrlName));
      
        if (department != null)
        {
            foreach (var product in GetProductsByTaxon(department.Title, "Departments"))
            {
                var parentPage = parent as PageSiteNode;
                var parentPageNode = GetPageManager().GetPageNode(parentPage.Id);
                childNodes.Add(GetSiteMapNodeForProduct(parentPageNode, product));
            }
        }
        return childNodes;
    }

    Is this the correct way to implement a custom SiteMapProvider in sitefinity? Are there any examples of a custom sitemap provider in Sitefinity 4.2 SP1.

    Thanks,
    Jason Chester
  2. Ivan Pelovski
    Ivan Pelovski avatar
    43 posts
    Registered:
    24 Sep 2012
    07 Oct 2011
    Link to this post
    Hi Jason Chester,

    We apologize for the late answer. We don't have a sample for custom site map. But what you did seams OK. Could you tell us when you stop to see the products in the navigation? We created a test project based on your code and it looks it works.

    Best wishes,
    Ivan Pelovski
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    07 Oct 2011
    Link to this post
    Jason, I am working on a Sitemap implementation myself, and will blog my solution soon...

    however I'm curious about your approach. Why do you use the sitemap and sitenodes? It might be easier to simply use the API to retrieve items (pages, news, products, etc) then build the xml manually, avoiding the sitemapnodes altogether. this is the approach I am taking.

    I don't know if this is related to your problem, but I think retrieving products through the API might automate internally the caching stuff so you can just grab the data you need (correct me if I'm wrong sf guys!)

    hope this is helpful, I'll try to publish my work asap!
  4. Jason Chester
    Jason Chester avatar
    11 posts
    Registered:
    03 Feb 2010
    07 Oct 2011
    Link to this post
    I decided to base my code on the existing sitemap implementation so I could take advantage of all the caching and performance built in to it. SitefinitySiteMap is a pretty complicated class and I wanted to maintain all it's functionality without duplicating the code.

    Inheriting from SitefinitySiteMap also means that I should be able to take advantage of any of the changes to the base implementation on version upgrades without having to change my code.

    I think the issues I have seen were more about my navigation control, based on CleanNav, than my sitemap provider.  After some debugging of the CleanNav code it is working well so I am happy with my approach.

    Jason
4 posts, 1 answered