Product Module - How to change Url? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Product Module - How to change Url?

  • Product Module - How to change Url?
  • Hi there,

    I've got my product module working and was able to get to he point of dropping a front end Listview control on the page. Clicking the product takes me to a detail view which brings me to my next question. The url that is generated has the date in the url, as if it was a news item or a blog post. This makes no sense for so many reasons. Can someone point me to the chunk of code that defines this and perhaps provide some suggestions on how this could be changed? Ideally I'd like to have a url that includes the category defined for the product or maybe a custom field that I allow the user to define.

    So instead of a url like this:

    I want to have:

    Thanks in advance for any help.
  • Hello Phill Hodgkinson,
    Hi Phill, you're completely right about this making no sense. And we should have provided a more practical sample of urls in the Products module. There are several ways to achive what you need here:

    1) The fast way to do is by overriding the CompileItemUrl<T> of the povider and return your custom build url.
    2) Override GetUrlFormat(ILocatable item)
    This returns a url formatting expression - the default one is actually "/[PublicationDate, 0:yyyy'/'MM'/'dd]/[UrlName]" and that is what you got in the Products Module.
    So basically, you can make your own formatting expressions based on the public properties of the ProductItem class.

    3) The formatting expression can be configured from the Provider configuration settings, by going into the backaned UI -> Advanced settings =>  ~/Sitefinity/Administration/Settings/Advanced, opening the Products configuration -> Providers - >OpenAccessProvider - > Parameters and adding a parameter with name urlFormat and with the value of your expression. This way you can change the url building also of the existing modules like News, Events etc. Important: currently you need to restart the applicaiton in order this to take effect , since we cache these settings - we will address this problem in a recent build.

    If you have a property in your expression that cannot be directly taken from the Public Properties of the prodduct item - like UrlName and PublishedDate,as the case with [category]. You can still use expression like "/CategoryName/UrlName". But you need to override protected virtual string GetUrlPart<T> - here you can make custom parsing of properties in the expression which cannot be resolved automatically.

    For example the method body can be
    if(key=="CategoryName") return GetCategoryNameForItem(item)
    return base.GetUrlPart ....

    All the best,
    Nikolay Datchev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • I have the similar problem.
    i have a web address as
    when i register the site example registered as moin

    then it need to be change as

    plz replay me as sson as possible.

    thnks & regds

  • Hi,

    Sitefinity uses relative and dynamic urls. You want to change the host, which actually is relative to the urls we use. Once you create a subdomain for your domain, you should change the project location. You need to move the project in the root of your subdomain.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  • So I followed #3 above, restarted the site, resaved all content items which worked great. In my urlFormat parameter, I set /[Title] to be the url. However, if my products items have spaces in the name, the space gets included in the url as opposed to a dash. Is there any way to modify this or am I going to have to rename all of my products items?

  • @Phil: did you managed to get this working? I'm also trying to get some nice url's based on filtering.

    I want to have the following scenario:

    - Category list on the left of the page
    - Company list on the right of the page
    - Click on a category and filter the list of companies.
    - The URL should then be:

    Any suggestions?

  • Phil, Were you able to figure this out? I would like to do the same, but I cant figure out how to use the GetCategoryNameForItem method to return the category name. Can you post your code?
  • If anybody still interested, here is the solution: