Skip to content

Commit

Permalink
add visibleOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
zzuutt committed Feb 21, 2017
1 parent 70b243e commit 34f3a35
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions core/lib/Thelia/Model/Category.php
Expand Up @@ -44,17 +44,21 @@ public function getRewrittenUrlViewName()
*
* @return int
*/
public function countAllProducts()
public function countAllProducts($visibleOnly = false)
{
$children = CategoryQuery::findAllChild($this->getId());
array_push($children, $this);

$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;
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 34f3a35

Please sign in to comment.