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

Changing the Product route

Vote:
 

Hi,

I am setting up an EPiServer Commerce solution and I am having a problem changing the first part of the url for where the product pages are displayed. According to the documentation, you can use two routes:

Hierarchial urls (CatalogRouteHelper.MapDefaultHierarchialRouter(routes, false)) Which sets the product url to follow the category that the product is placed in

and

SEO urls (CatalogRouteHelper.MapDefaultHierarchialRouter(routes, true)) Which sets the product url to be in the root of the website, i.e. http:///.aspx

My request is simple and therefore I hope that the solution is as well. 

How do I place the SEO approach under a path in the url. i.e. I want the SEO url to be placed under the path "products" so the url for all products becomes http:///products/.aspx

I recon it should be simple, but I can't seem to make it work.

Thanks for your time.

#117101
Feb 11, 2015 18:35
Vote:
 

Hi,

I believe you can create your implementation of HierarchicalCatalogPartialRouter, which overrides the method 

public virtual PartialRouteData GetPartialVirtualPath(CatalogContentBase content, string language, RouteValueDictionary routeValues, RequestContext requestContext)

when return the PartialRouteData, instead of StartPage 

return new PartialRouteData { BasePathRoot = ContentReference.StartPage, PartialVirtualPath = seoUri };
}

You can set BasePathRoot to the products content link.

Then instead of using CatalogRouteHelper, register your new router:

var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var commerceRootContent = contentLoader.Get<CatalogContentBase>(referenceConverter.GetRootLink());
routes.RegisterPartialRouter(new YourRouter(startingPoint, commerceRootContent, enableOutgoingSeoUri));

Warning: I did not try it, there's no guarantee it'll work, but it seems to be :)

Good luck.

/Q

#117150
Edited, Feb 12, 2015 12:40
Vote:
 

Hi,

Thanks for your reply.

I have tried messing with that. However it seems that all the "GetPartialVirtualPath" does is to update the links in the CMS interface to point to http://<hostname>/products/categoryname/<productname>.aspx in the Hierarchial routing, not in the SEO routing.

I don't believe that the code in the HierarchicalCatalogPartialRouter is run when a producted is visited through the SEO URL.

Furthermore I am having a hard time looking up a product through the API, based on the SEO url.

Thanks again for your reply.

#117154
Feb 12, 2015 13:03
Vote:
 

Hi,

ICatalogSystem (and its default implementation) has a method GetCatalogEntryByUriDto(string uri, string languageCode, CatalogEntryResponseGroup responseGroup); (and overloads). You can use it to get the content you need.

Not the most optimized way but it works :)

/Q

#117158
Feb 12, 2015 13:29
Vote:
 

Yeah, I did read a blog post from this clever guy... and I generally got the feeling that ICatalogSystem should be avoided

http://world.episerver.com/Blogs/Quan-Mai/Dates/2014/10/Moving-away-from-ICatalogSystem-part-0/

#117160
Feb 12, 2015 13:56
Vote:
 

Yes, it should be avoided when possible, but until we have complete replacement of ICatalogSystem in new content API:s, then, well...

:)

/Q

#117161
Feb 12, 2015 14:14
Vote:
 

Hi guys

I have the same issue like Rene is having.

@Rene: Where you able to fix it?

Thanks

Juan 

#140614
Oct 25, 2015 23:43
* 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.