diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 2788f0c9a4..e27f08d671 100644 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -44,7 +44,7 @@ public function getRewrittenUrlViewName() * * @return int */ - public function countAllProducts() + public function countAllProducts($visibleOnly = false) { $children = CategoryQuery::findAllChild($this->getId()); array_push($children, $this); @@ -52,9 +52,13 @@ public function countAllProducts() $countProduct = 0; foreach ($children as $child) { - $countProduct += ProductQuery::create() - ->filterByCategory($child) - ->count(); + $req = ProductQuery::create(); + $req->filterByCategory($child); + if($visibleOnly) { + $req->filterByVisible(true); + } + + $countProduct += $req->count(); } return $countProduct; @@ -70,19 +74,7 @@ public function countAllProducts() */ public function countAllProductsVisibleOnly() { - $children = CategoryQuery::findAllChild($this->getId()); - array_push($children, $this); - - $countProduct = 0; - - foreach ($children as $child) { - $countProduct += ProductQuery::create() - ->filterByCategory($child) - ->filterByVisible(true) - ->count(); - } - - return $countProduct; + return countAllProducts(true); } /**