Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Gustas Sagaitis 14 posts 93 karma points
    Jan 20, 2014 @ 13:50
    Gustas Sagaitis
    0

    How does CatalogLibrary.GetNiceUrlFor* work?

    Hi,

    I am trying to build multilingual website with webshop. I have home node for each language. Each home node has some content pages and Shop node (uCommerce). Home nodes are configured with hostnames like site.com/da/ or site.com/en/. So structure is like this:

    Page      Danish                                  English
    
    Shop     site.com/da/shop.aspx                    site.com/en/shop.aspx
    Catalog  site.com/da/shop/catalog.aspx            site.com/en/catalog.aspx
    Product  site.com/da/shop/catalog/product.aspx    site.com/en/shop/catalog/product.aspx
    

    So this works ok. On top of this there is some URL rewriting rules for each page/language. So url

    site.com/da/whatever-here/c-11/c-22/p-33
    

    points to

    site.com/da/shop/catalog/product.aspx?catalog=11&category=22&product=33
    

    or somethigs similar.

    So now how do I make Ucommerce.Api.CatalogLibrary.GetNiceUrlFor* methods return correct path with /da/ or /en/ or whatnot prefix? Is there another way to do what I describe here? Should I manually generate urls somehow? How does GetNiceUrlFor* know what to put in front of /c-11/c-22/p-33?

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 20, 2014 @ 14:01
    Morten Skjoldager
    0

    Hello Gustas,

    It only uses relative paths, so it would point to the right hostname as long as you're on the hostname allready. It also takes care of giving you the right url in the right language. 

    Hope that helps.

    Best regards

    Morten

  • Gustas Sagaitis 14 posts 93 karma points
    Jan 20, 2014 @ 14:51
    Gustas Sagaitis
    0

    Hi Morten,

    Relative path to site root, yes. This code

    @foreach(var cat in catalog.GetRootCategories())
    {
        string niceUrl = @CatalogLibrary.GetNiceUrlForCategory(cat, catalog);
        <li><a href="@niceUrl">@cat.Name </a></li>
    }
    

    produces niceUrl that starts with '/'. So niceUrl in this case will be something like /store-name/category-name/c-22/c-33. Correct form would be /en/store-name/category-name/c-22/c-33. Any ideas?

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 20, 2014 @ 15:47
    Morten Skjoldager
    1

    Can't you just concatinate from what the hostname is at the point ? 

    So you would get the url for the site that would either be site.com/da or site.com/en and then concatinate /store-name/category-name/c-22/c-33

    Regards

    Morten

  • Gustas Sagaitis 14 posts 93 karma points
    Jan 20, 2014 @ 15:59
    Gustas Sagaitis
    100

    Hi Morten,

    Thanks for reply. I ended up doing this

    <ul>
    @{
        var language = SiteContext.Current.CurrentCulture.TwoLetterISOLanguageName;
    }
    @foreach(var cat in catalog.GetRootCategories())
    {
        string niceUrl = @CatalogLibrary.GetNiceUrlForCategory(cat, catalog);
        <li><a href="@String.Format("/{0}{1}", language, niceUrl)">@cat.Name </a></li>
    }
    
    </ul>
    

    Work pretty well as long as you keep naming different language sites using same scheme.

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 20, 2014 @ 16:13
    Morten Skjoldager
    0

    Great to hear. 

    Regards

    Morten

Please Sign in or register to post replies

Write your reply to:

Draft