49 \
Magento\Catalog\Model\CategoryFactory $categoryFactory,
52 $this->_categoryTree = $categoryTree;
54 $this->_categoryFactory = $categoryFactory;
55 $this->_withProductCount =
true;
56 parent::__construct($context,
$data);
66 return $this->_coreRegistry->registry(
'category');
77 return \Magento\Catalog\Model\Category::TREE_ROOT_ID;
96 return \Magento\Catalog\Model\Category::TREE_ROOT_ID;
105 if ($root && $root->getId()) {
117 return $this->_storeManager->getStore(
$storeId);
126 public function getRoot($parentNodeCategory =
null, $recursionLevel = 3)
128 if ($parentNodeCategory !==
null && $parentNodeCategory->getId()) {
129 return $this->
getNode($parentNodeCategory, $recursionLevel);
131 $root = $this->_coreRegistry->registry(
'root');
132 if ($root ===
null) {
137 $rootId =
$store->getRootCategoryId();
142 $tree = $this->_categoryTree->load(
null, $recursionLevel);
145 $tree->loadEnsuredNodes($this->
getCategory(), $tree->getNodeById($rootId));
150 $root = $tree->getNodeById($rootId);
153 $root->setIsVisible(
true);
155 $root->setName(
__(
'Root'));
158 $this->_coreRegistry->register(
'root', $root);
169 return \Magento\Store\Model\Store::DEFAULT_STORE_ID;
180 $collection = $this->_categoryFactory->create()->getCollection();
184 )->addAttributeToSelect(
186 )->setProductStoreId(
188 )->setLoadProductCount(
189 $this->_withProductCount
211 $root = $this->_coreRegistry->registry(
'root');
212 if (
null === $root) {
213 $ids = $this->_categoryTree->getExistingCategoryIdsBySpecifiedIds($ids);
214 $tree = $this->_categoryTree->loadByIds($ids);
216 $root = $tree->getNodeById($rootId);
218 $root->setIsVisible(
true);
220 $root->setName(
__(
'Root'));
224 $this->_coreRegistry->register(
'root', $root);
234 public function getNode($parentNodeCategory, $recursionLevel = 2)
236 $nodeId = $parentNodeCategory->getId();
237 $node = $this->_categoryTree->loadNode($nodeId);
238 $node->loadChildren($recursionLevel);
241 $node->setIsVisible(
true);
243 $node->setName(
__(
'Root'));
257 $params = [
'_current' =>
false,
'_query' =>
false,
'store' => $this->
getStore()->getId()];
268 'catalog/category/edit',
269 [
'store' =>
null,
'_query' =>
false,
'id' =>
null,
'parent' =>
null]
280 $ids = $this->
getData(
'root_ids');
283 foreach ($this->_storeManager->getGroups() as
$store) {
284 $ids[] =
$store->getRootCategoryId();
286 $this->
setData(
'root_ids', $ids);
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTree, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, array $data=[])
getData($key='', $index=null)
getNode($parentNodeCategory, $recursionLevel=2)
elseif(isset( $params[ 'redirect_parent']))
getRoot($parentNodeCategory=null, $recursionLevel=3)
getUrl($route='', $params=[])
getSaveUrl(array $args=[])
setData($key, $value=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]