/** * Initialize categories ID to text-path hash. * * @return $this */ protected function initCategories() { $collection = $this->_categoryColFactory->create()->addNameToResult(); /* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */ foreach ($collection as $category) { $structure = preg_split('#/+#', $category->getPath()); $pathSize = count($structure); if ($pathSize > 1) { $path = []; for ($i = 1; $i < $pathSize; $i++) { $path[] = $collection->getItemById($structure[$i])->getName(); } $this->_rootCategories[$category->getId()] = array_shift($path); if ($pathSize > 2) { $this->_categories[$category->getId()] = implode('/', $path); } } } return $this; }