Getting a Products Category
Getting a Products Category
Is there any way of getting a category by using the Product? I am having trouble figuring out how to bring back the product's category
Re: Getting a Products Category
Well product object contains a member called Categories that returns the ids of parent categories for product. A product can be assigned to multiple categories that's why product.Categories returns list of ids.
If your product has only one parent then you can simply get the parent category via something like this
If product belongs to multiple categories the perhaps you need to do the following in order get all parent categories
If your product has only one parent then you can simply get the parent category via something like this
Code: Select all
Category category = CategoryDataSource.Load(product.Categories[0]);
Code: Select all
foreach (int categoryId in product.Categories)
{
Category category = CategoryDataSource.Load(categoryId);
//do the stuff with loaded category here
}