cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to change the category navigation URL

0 Kudos
195

HI,

we would like to change the category url from the standard one ({category-name}/c/{category-id}) to a custom one ({category-name}~{category-id}. This change should support category in all level. for example - if we have category A with id 1 and sub-category B with id 2, the url for them will be:

A url: ..../a~1

B url: ..../a~1/b~2

is this something that can be done?

Accepted Solutions (0)

Answers (1)

Answers (1)

adiputera
Active Participant
0 Kudos

it's possible to change the URL format of your PLP, all you need to do is override OOTB class: DefaultCategoryModelUrlResolver.resolveInternal

This is the OOTB code for PLP, you can build and return your custom URL in this method, if you want to remove the /c/ and change it to something else, you need to also modify the controller

@Override
protected String resolveInternal(final CategoryModel source)
{
// Work out values

// Replace pattern values
String url = getPattern();
if (url.contains("{baseSite-uid}"))
{
url = url.replace("{baseSite-uid}", urlEncode(getBaseSiteUid().toString()));
}
if (url.contains("{category-path}"))
{
final String categoryPath = buildPathString(getCategoryPath(source));
url = url.replace("{category-path}", categoryPath);
}
if (url.contains("{category-code}"))
{
final String categoryCode = urlEncode(source.getCode()).replace("+", "%20");
url = url.replace("{category-code}", categoryCode);
}
if (url.contains("{catalog-id}"))
{
url = url.replace("{catalog-id}", urlEncode(source.getCatalogVersion().getCatalog().getId()));
}
if (url.contains("{catalogVersion}"))
{
url = url.replace("{catalogVersion}", urlEncode(source.getCatalogVersion().getVersion()));
}

return url;

}