If your requirement is to show the list of categories and the count of products under that category then there are two approaches for this
1. You can use commerce server object model, get categories for a catalog and for each category, get product count. Populate data in table/object and send it back to front end. Trust me it will take lot of time to fetch these details.
2. You can directly access database and fetch these details. Note: Microsoft doesn’t recommend to access database directly. Here is the code to fetch product count group by category.
Select A.CategoryName, B.Products from [MyCatalog_CatalogProducts] A
Join
(
SELECT [ParentOID]
, Count([OID]) as Products
FROM [MyCatalog_CatalogProducts]
Group by [ParentOID] ) B
On A.OID = B.ParentOID
where CategoryName is not null
If you like this post, please click on our sponsor advertisement.
