November Happy Hour will be moved to Thursday December 5th.

Routing on Commerce NodeContent

Vote:
 

I am currently trying to add a custom router in Commerce version 10.8.0 that allows me to write the following URL: website.com/gloves/{brand}, where gloves is a NodeContent in my catalog and {brand} is a segment I would like to perform some logic on before routing to the controller.

    public class CustomCategoryPartialRouter : HierarchicalCatalogPartialRouter
    {
        //neye category is a EPiServer catalog
        //this partial router allows a brand to be defined in the succeeding URL segment to filter on brand within the catalog
        public CustomCategoryPartialRouter(Func routeStartingPoint, CatalogContentBase commerceRoot,
            bool enableOutgoingSeoUri) : base(routeStartingPoint, commerceRoot, enableOutgoingSeoUri)
        {
        }

        public override PartialRouteData GetPartialVirtualPath(CatalogContentBase content, string language,
            RouteValueDictionary routeValues, RequestContext requestContext)
        {
            return base.GetPartialVirtualPath(content, language, routeValues, requestContext);
        }


        public override object RoutePartial(PageData content, SegmentContext segmentContext)
        {
            return base.RoutePartial(content, segmentContext);
        }
    }

I have ensured that the route is registered in the initialization module:

    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class CatalogRouteInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {

            CatalogContentBase commerceRoot = ServiceLocator.Current.GetInstance().Get(ServiceLocator.Current.GetInstance().GetRootLink());
            RouteTable.Routes.RegisterPartialRouter(new CustomCategoryPartialRouter(() =>
            {
                if (!ContentReference.IsNullOrEmpty(SiteDefinition.Current.StartPage))
                    return SiteDefinition.Current.StartPage;
                return SiteDefinition.Current.RootPage;
            }, commerceRoot, true));
            //CatalogRouteHelper.MapDefaultHierarchialRouter(RouteTable.Routes, true);
        }

        public void Preload(string[] parameters) { }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }

When I try access website.com/gloves, my RoutePartial function in my PartialRouter is not being called before the routing has already occured.

Anyone got any idea why this occurs and how to fix it?

Thanks in advance!

#192331
Edited, May 15, 2018 13:16
Vote:
 

Because gloves is a NodeContent, so you have to make it the commerceRoot instead of the normal commerceRoot as in your code. (or actually its parent node as the commerceRoot - I'm not so sure about it now but you can try) 

#192429
Edited, May 16, 2018 17:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.