/** * Get category tree * * @param int|null $rootNode * @param bool $reload * @return \Magento\Framework\Data\Tree\Node */ protected function getTree($rootNode = null, $reload = false) { if (!$this->categoryTree || $reload) { if ($rootNode === null) { $rootNode = $this->storeManager->getStore()->getRootCategoryId(); } $tree = $this->resourceCategoryTreeFactory->create(); $node = $tree->loadNode($rootNode)->loadChildren(); $tree->addCollectionData(null, false, $rootNode); $this->categoryTree = $node; } return $this->categoryTree; }