Hi. We have a client who wants to be able to use blocks on product pages and category pages. This has been solved with the landing page logic so when a category page or productpage being built fetches these blocks and renders in the views.
The problem is the client want to be able to link to these landing pages (actually the products or categories) but when using the editor your only option is to pick a page (the landing page) or manually copy the url to the category or product and paste it as a link in the editor.
the client doesn’t want a wrapping category (like products/category1/product1, products/category2/product2) and wants a url-style like this: category1/product1 and category2/product2
example:
category has url domain.com/category
landing page get url domain.com/category_1 (because named the same in root level of pages and products)
So if you pick the landing page as source in the editor it will get the url of the landing page.
We made a solution for fields when pointing out a page where we check if it’s a landing page and fetch the URL of the select category or product. via exentsions of the link model. But this solution we cannot apply to the editors fetching of urls.
private static LinkModel ConvertLinkModel(Page item)
{
var linkModel = item.MapTo<LinkModel>();
var fieldTemplateService = IoC.Resolve<FieldTemplateService>();
var fieldTemplate = fieldTemplateService.Get<PageFieldTemplate>(item.FieldTemplateSystemId);
if (fieldTemplate.Id == PageTemplateNameConstants.Landing)
{
var baseProductService = IoC.Resolve<BaseProductService>();
var categoryService = IoC.Resolve<CategoryService>();
var productPointer = item.Fields.GetValue<PointerItem>(PageFieldNameConstants.ProductPointer);
var categoryPointer = item.Fields.GetValue<PointerItem>(PageFieldNameConstants.CategoryPointer);
if(productPointer != null)
{
linkModel = baseProductService.Get(productPointer.EntitySystemId).MapTo<LinkModel>();
}else if(categoryPointer != null)
{
linkModel = categoryService.Get(categoryPointer.EntitySystemId).MapTo<LinkModel>();
}
}
return linkModel;
}
Litium version: 7.2