Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Manager;
- use App\Entity\Category;
- class ProductManager
- {
- /**
- * @var int
- */
- public $count;
- public function __construct()
- {
- $this->count = 0;
- }
- /**
- * @param Category|null $category
- * @return int
- */
- public function getItemsCountFotCategory(?Category $category): int
- {
- foreach ($category->getChildren() as $child)
- {
- if ($category->getProducts() !== null) {
- $this->count += $category->getProducts()->count();
- }
- if ($child->getChildren() !== null) {
- $this->getItemsCountFotCategory($child);
- } else {
- continue;
- }
- }
- return $this->count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement