vendor/shopware/core/Content/Category/Tree/TreeItem.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Category\Tree;
  3. use Shopware\Core\Content\Category\CategoryEntity;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\Framework\Struct\Struct;
  6. #[Package('content')]
  7. class TreeItem extends Struct
  8. {
  9.     /**
  10.      * @internal public to allow AfterSort::sort()
  11.      */
  12.     public ?string $afterId;
  13.     /**
  14.      * @var CategoryEntity
  15.      */
  16.     protected $category;
  17.     /**
  18.      * @var TreeItem[]
  19.      */
  20.     protected $children;
  21.     public function __construct(?CategoryEntity $category, array $children)
  22.     {
  23.         $this->category $category;
  24.         $this->children $children;
  25.         $this->afterId $category $category->getAfterCategoryId() : null;
  26.     }
  27.     public function getId(): string
  28.     {
  29.         return $this->category->getId();
  30.     }
  31.     public function setCategory(CategoryEntity $category): void
  32.     {
  33.         $this->category $category;
  34.         $this->afterId $category->getAfterCategoryId();
  35.     }
  36.     public function getCategory(): CategoryEntity
  37.     {
  38.         return $this->category;
  39.     }
  40.     public function getChildren(): array
  41.     {
  42.         return $this->children;
  43.     }
  44.     public function addChildren(TreeItem ...$items): void
  45.     {
  46.         foreach ($items as $item) {
  47.             $this->children[] = $item;
  48.         }
  49.     }
  50.     public function setChildren(array $children): void
  51.     {
  52.         $this->children $children;
  53.     }
  54.     public function getApiAlias(): string
  55.     {
  56.         return 'category_tree_item';
  57.     }
  58. }