diff --git a/src/Model/Category/CategoryCollection.php b/src/Model/Category/CategoryCollection.php index d68b1b11a4..b13df932ac 100644 --- a/src/Model/Category/CategoryCollection.php +++ b/src/Model/Category/CategoryCollection.php @@ -33,6 +33,7 @@ protected function indexRow($offset, $row) $id = isset($row[static::ID]) ? $row[static::ID] : null; $parentId = isset($row[static::PARENT][static::ID]) ? $row[static::PARENT][static::ID] : null; } + $this->addToIndex(static::ID, $offset, $id); foreach ($slugs as $locale => $slug) { $locale = \Locale::canonicalize($locale); $this->addToIndex(static::SLUG, $offset, $locale . '-' . $slug); @@ -44,6 +45,18 @@ protected function indexRow($offset, $row) } } + /** + * @param $id + * @return Category|null + */ + public function getById($id) + { + return $this->getBy(static::ID, $id); + } + + /** + * @return Category[] + */ public function getRoots() { $elements = []; @@ -53,6 +66,10 @@ public function getRoots() return $elements; } + /** + * @param $parentId + * @return Category[] + */ public function getByParent($parentId) { $elements = [];