Search results item Primary Parent Category
I am trying to get the primary parent category an item belongs to when returned in a search result. I find however that these always seem to be null.
Is there a way to get the primary parent category an item belongs to in a search result as I need to create a link to the category in which the product exists for each item in the search result. (info: I am using the CS 2007 starter site)
// Select catalogSearch.SearchOptions.SortProperty = "cy_list_price"; // From Response.Write("Total Records: " + totalRecords.ToString()); foreach (CatalogItemsDataSet.CatalogItem catalogItem in catalogItems.CatalogItems) Response.Write(catalogItem["ItemNumber"].ToString() + " - " + catalogItem["AuthorName"]);
CatalogContext catalogContext = CommerceComponents.Helpers.CatalogHelper.CatalogContext;
CatalogSearch catalogSearch = catalogContext.GetCatalogSearch();
catalogSearch.SearchOptions.ClassTypes = CatalogClassTypes.ProductClass |
CatalogClassTypes.ProductFamilyClass |
CatalogClassTypes.ProductFamilyForVariantsClass;
catalogSearch.SearchOptions.SortDescending = true;
catalogSearch.SearchOptions.PropertiesToReturn = SiteContext.Configuration.PropertiesToReturn;
catalogSearch.FreeTextSearchPhrase = @"Harry";
catalogSearch.CatalogNames = @"AU DD CM Base Catalog";
int totalRecords = 0;
CatalogItemsDataSet catalogItems = catalogSearch.Search(out totalRecords);
{
Response.Write(catalogItem.ProductId.ToString());
Response.Write(catalogItem.PrimaryParentCategoryName.ToString());
}

