The Catalog System can be thought of as the Heart of Commerce Server. Products and categories can be defined in a hierarchical manner within a Catalog. To get all categories exist within a Catalog and products associated with a category can be retrieved using Commerce Server API.
Below is a small example which shows how to get list of all the categories of a Catalog.
Example 1:
//Get the instance of the CatalogContext using ServiceAgent CatalogServiceAgent catalogServiceAgent; catalogServiceAgent = new CatalogServiceAgent(" http://localhost/CatalogWebService/CatalogWebService.asmx"); CatalogContext catalogContext = CatalogContext.Create(catalogServiceAgent); //Get the ProductCatalog by its Name ProductCatalog catalog = catalogContext.GetCatalog("Mindfire"); //Get the root category of the ProductCatalog Category category = catalog.GetRootCategory(); //Get all the categories of the Catalog CategoryCollection categoryCollection = category.ChildCategories;
Below example shows how to get the Product associated with a particular Category.
Example 2:
//Get the Cataegory of a Catalog by its name Category myCategory = catalog.GetCategory("CategoryMindfire"); //Get all the Products belongs to that Category ProductCollection productCollection = myCategory.ChildProducts;