Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
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!