Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

Setting a NodeContent as the catalog root using the HierarchicalCatalogPartialRouter

$
0
0

Hi,

I am trying to set the Node content as the catalog root. Below is my catalog structure:

https://www.screencast.com/t/5tMhOWSBJDk

I want to make the Test Node the root for all the children Node Contents under it. And below is my code 

using System;
using System.Configuration;
using System.Linq;
using System.Web.Routing;
using EPiServer;
using EPiServer.Commerce.Routing;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Web;
using EPiServer.Web.Routing;
using Mediachase.Commerce.Catalog;
namespace Foundation.Infrastructure
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class Initialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            var referenceConverter = context.Locate.Advanced.GetInstance<ReferenceConverter>();
            var contentRepository = context.Locate.Advanced.GetInstance<IContentRepository>();
            var rootLink = referenceConverter.GetRootLink();
            var root = contentRepository.GetChildren<EPiServer.Commerce.Catalog.ContentTypes.CatalogContent>(rootLink).FirstOrDefault();
            var rootNodeContent = contentRepository.GetChildren<EPiServer.Commerce.Catalog.ContentTypes.NodeContent>(root.ContentLink).FirstOrDefault();
            var hierarchicalCatalogPartialRouter = new HierarchicalCatalogPartialRouter(() => SiteDefinition.Current.StartPage, rootNodeContent, false);
            RouteTable.Routes.RegisterPartialRouter(hierarchicalCatalogPartialRouter);
        }
        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}

But I still see the routing has not changed, it still is for exmaple: www.example.com/shopping/testnode/cookware/

Since I made the the first NodeContent the root, I was expecting it to be like: www.example.com/testnode/cookware/

Am I missing something here?


Viewing all articles
Browse latest Browse all 6894

Trending Articles