I need to get Product count and minimum price of Parent category (count and minimum price should calculate from all its child categories). I use following code
$categoryHelper = $this->helper('Magento\Catalog\Helper\Category');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
foreach($categoryHelper->getStoreCategories() as $category):
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($category->getId());
$_outputhelper = $this->helper('Magento\Catalog\Helper\Output');
$products = $category->getProductCollection()->addAttributeToSelect('*')->setOrder('price','ASC')->setPageSize(1);
$fromprice = 0;
foreach($products as $product){
$fromprice = $product->getPrice();
}
$count = $category->getProductCount();
endforeach;
but above code give product count and minimum price from only parent categories. Can any one help so that code calculate from child categories?
Also getProductCount() give wrong result. Its include all products even disabled products
Thanks
Try this to get the subcategory with the current category:
$subcategory = $category->getChildrenCategories();
foreach($subcategory as $subcat) {
echo $subcat->getName();
}