Try our conversational search powered by Generative AI!

Catalog routing for product and category

Vote:
 

Hello

I'm trying to get the following URL structure for my Commerce:

Product directly on root:

{base-url}/en-gb/{product-segment}

Category path but without catalogue name:

{base-url}/en-gb/{category-1-segment}/{category-2-segment} etc.

I've been able to remove the catalogue name with the following code in my initiallization module:

var referenceConverter = context.Locate.Advanced.GetInstance<ReferenceConverter>();
var contentLoader = context.Locate.Advanced.GetInstance<IContentLoader>();
var commerceRootContent = contentLoader.GetChildren<CatalogContent(referenceConverter.GetRootLink()).FirstOrDefault();
Func<ContentReference> startingPoint = () => ContentReference.IsNullOrEmpty(SiteDefinition.Current.StartPage) ?
                SiteDefinition.Current.RootPage :
                SiteDefinition.Current.StartPage;
RouteTable.Routes.RegisterPartialRouter(new HierarchicalCatalogPartialRouter(startingPoint, commerceRootContent, false));

However I've been unsuccesful achieving the desired outcome. Anyone been succesful with this?

Commerce v13.7.1

CMS v11.13.0

Thanks in advance,

Benjamin Sorterup

#210965
Dec 13, 2019 17:25
Vote:
 

Hey Benjamin,

There is a nice blog post about this, this will be helpful for you..

https://world.episerver.com/blogs/reimonds-blog---episerver-developer/dates/2017/11/episerver-cms-and-commerce-custom-routing/

#210997
Dec 16, 2019 9:02
Vote:
 

Hey Benjamin,

There was a similar discussion in the past where community member had pointed out what Quan had explained in his book how to remove catalog from URL. you should follow that approach instead. That approach will ensure your URL structure will continue to work even when your product is directly underneath the catalog root.

https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2019/2/remove-catalog-name-from-product-url/

~ Sujit

#211208
Dec 19, 2019 23:12
* 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.