Copied to clipboard

Flag this post as spam?

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


  • mostafa 17 posts 90 karma points
    Aug 09, 2016 @ 08:47
    mostafa
    0

    Product Category and its details

    Hello all ,

    I have website building it in umbraco 7.4.3 , and it has a products section consist of categories say (cat1,cat2...) and I have created a document type for that category (to be added dynamically by the admin) contains the category name and description. then I have created a product details document type contains product name, description ,image for that product then category which is mentioned above and it's in a dropdown list and I used a northernground.ucontentdropdown , what I want to do is to get products by category , how can I do that ? if any body get what I mean may send me help please.

    Regards

  • Lucio 24 posts 142 karma points
    Aug 09, 2016 @ 10:14
    Lucio
    0

    Hope this helps

    //Category you are looking for
    string categoryName = "The category you want to look for";
    
    //Having that you have everithing under home node  
    var home = Model.Content.AncestorOrSelf(1);
    
    //Select the category node using the category name
    var category = home.Descendants("category").Where(c => c.GetPropertyValue<string>("name") == categoryName).ToList();
    
    if(category != null && category.Count > 0)
    {
        //Having that northernground.ucontentdropdown store the nodeId and it does as string
        string categoryId = category.First().Id.ToString();
    
        //Get all the products and filter them by the selected category
        return home.Descendants("productsDetails").Where(p => p.GetPropertyValue<string>("category") == categoryId).ToList();
    }
    
    return null;
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies