How to use a custom url in the Products module - Solution

Posted by Community Admin on 03-Aug-2018 03:02

How to use a custom url in the Products module - Solution

All Replies

Posted by Community Admin on 14-Jul-2011 00:00

Hi,

If anybody is looking for a way to generate a seo friendly url with the category in it, then please use the following code-snippet for your module. The url will change from /2011/01/28/product-name to /category/product-name. This code needs to be placed in your openaccessdataprovider.cs.

Hope this helps somebody. I would not have been able to figure this out without the help of the amazing telerik support team - kudos to them.

 public override string GetUrlFormat(ILocatable item)
 
     return "/[CategoryName]/[UrlName]";
 
 
 protected override string GetUrlPart<T>(string key, string format, T item)
 
     if (key == "CategoryName")
     
         return this.GetCategoryNameForItem(item);
     
     return base.GetUrlPart<T>(key, format, item);
 
 
 protected string GetCategoryNameForItem(IDataItem item)
 
     if (item == null)
     
         throw new ArgumentNullException("item");
     
     string category = string.Empty;
     IContent content = (IContent)item;
 
     IList<Guid> categoryIds = ((ProductItem)item).GetValue<IList<Guid>>("Category");
     Guid firstCategoryId = categoryIds.FirstOrDefault();
     if (Guid.Empty != firstCategoryId)
     
         var taxonManager = TaxonomyManager.GetManager();
         category = taxonManager.GetTaxon(firstCategoryId).Name;
         category = Regex.Replace(category, "[^a-zA-Z0-9]", "-");
     
 
     return category;
 

Posted by Community Admin on 14-Jul-2011 00:00

Hi Sonu,

Thank you for sharing this with the community. This will truly help a lot of people and save them time. We really appreciate when our clients actively share knowledge and help each other.

Kind regards,
Stanislav Velikov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 14-Jul-2011 00:00

My pleassure Stanislav. It would have not been possible without your help. Thanks again.

Posted by Community Admin on 12-Sep-2012 00:00

Absolutely, a great help.  I suggest Sitefinity team to start a knowledge base where they can publish with their solutions to clients problems.  I am concern with solutions to problems that more than one site are facing.  Knowledge base applications have more powerful search engines.

Thanks,
Zia

Posted by Community Admin on 12-Sep-2012 00:00

Absolutely, a great help.  I suggest Sitefinity team to start a knowledge base where they can publish with their solutions to clients problems.  I am concern with solutions to problems that more than one site are facing.  Knowledge base applications have more powerful search engines.

Thanks,
Zia

This thread is closed