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.

  • Filip Lundby 128 posts 149 karma points
    Jan 29, 2014 @ 16:50
    Filip Lundby
    0

    Output category name on productcard

    I'm outputting the category name on the productlist - which works fine:

    var category = SiteContext.Current.CatalogContext.CurrentCategory;
    <h1>@category.DisplayName()</h1>
    

    But if I try the same lines of code in the productcard, "category" will always be null.

    Does this have to do with a product being able to have multiple categories?

     

     

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Jan 29, 2014 @ 16:54
    Nickolaj Lundgreen
    0

    If the URI is correct you should be able to the the current category by context.

    Could you post the relative URL for the product page?

    (It should look something like this: /niceUrlCategory/contextCategory/productName/c-1/c-2/p-3 )

  • Filip Lundby 128 posts 149 karma points
    Jan 30, 2014 @ 11:15
    Filip Lundby
    0

    Hi Nickolaj. I see that that the category context is missing from my produktcard URI

    Productlist URI: /produkter/tilbehoer/c-23/c-69

    Productcard URI: /produkter/sort-stol/c-23/p-105

    Perhaps I am missing something in my productlist...?

    var category = SiteContext.Current.CatalogContext.CurrentCategory;
    foreach (var cat in category.Categories) {
    var products = CatalogLibrary.GetProducts(cat);
    @foreach (var product in products) {
    <a href="@CatalogLibrary.GetNiceUrlForProduct(product)">Product</a>
    }

     

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Jan 30, 2014 @ 11:28
    Nickolaj Lundgreen
    100

    Hi skooter You need to use the UCommerce.Api.CatalogLibrary.GetNiceUrlForProduct(product,category) overload, to get the category context on the product page :)

  • Filip Lundby 128 posts 149 karma points
    Jan 30, 2014 @ 12:09
    Filip Lundby
    0

    Thankyou very much Nickolaj. That did it :-)

Please Sign in or register to post replies

Write your reply to:

Draft