private static function updateProductCount(Category $category) { $countTotal = $countAvailable = $countActive = 0; foreach ($category->getSubCategorySet() as $sub) { self::updateProductCount($sub); $countTotal += $sub->totalProductCount->get(); $countAvailable += $sub->availableProductCount->get(); $countActive += $sub->activeProductCount->get(); } $category->totalProductCount->set($category->totalProductCount->get() + $countTotal); $category->activeProductCount->set($category->activeProductCount->get() + $countActive); $category->availableProductCount->set($category->availableProductCount->get() + $countAvailable); $category->save(); }