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.

  • Tony Kiernan 278 posts 341 karma points
    Jul 17, 2011 @ 21:38
    Tony Kiernan
    0

    List all categories a product is in on it's details page

    Any suggestions on how to do this?  I've been poking about the documentation and intellisense all day and not getting anywhere near it.

    I'm using Razor

  • Lasse Eskildsen 34 posts 57 karma points
    Jul 21, 2011 @ 11:22
    Lasse Eskildsen
    0

    Hi Tony,

    There's a GetCategories() method on UCommerce.EntitiesV2.Product, which will give you the categories for the product.

  • Christian Wendler 46 posts 155 karma points
    Jul 22, 2011 @ 17:20
    Christian Wendler
    0

    If someone wants this feature for XSLT, put the following function in a XSLT extension class and enjoy:

      public static XPathNodeIterator GetProductCategories(string sku) {

       XmlDocument xmlDoc = new XmlDocument();

       try {
        var product = UCommerce.EntitiesV2.Product.Find(p => p.Sku == sku && p.VariantSku == null).Single();
        var categories = product.GetCategories();

        if(categories.Count() > 0) {

         CategoryRenderer cr = new CategoryRenderer(new PropertyRenderer());
         return cr.RenderDocument(categories, "categories").CreateNavigator().Select(".");

        }

        xmlDoc.LoadXml("<categories />");
        return xmlDoc.CreateNavigator().Select(".");

       }
       catch(Exception ex) {
        xmlDoc.LoadXml("<error><message>" + ex.Message + "</message><stack>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</stack></error>");
        return xmlDoc.CreateNavigator().Select(".");
       }

      }

Please Sign in or register to post replies

Write your reply to:

Draft