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.
//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;
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
Hope this helps
is working on a reply...