예제 #1
0
 /**
  * Retrieve categories
  *
  * @param integer $parent
  * @param integer $recursionLevel
  * @param boolean|string $sorted
  * @param boolean $asCollection
  * @param boolean $toLoad
  * @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Category\Collection
  */
 public function getCategories($parent, $recursionLevel = 0, $sorted = false, $asCollection = false, $toLoad = true)
 {
     $tree = $this->_categoryTreeFactory->create();
     /* @var $tree \Magento\Catalog\Model\Resource\Category\Tree */
     $nodes = $tree->loadNode($parent)->loadChildren($recursionLevel)->getChildren();
     $tree->addCollectionData(null, $sorted, $parent, $toLoad, true);
     if ($asCollection) {
         return $tree->getCollection();
     }
     return $nodes;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
파일: Category.php 프로젝트: kid17/magento2
 /**
  * Retrieve category tree model
  *
  * @return \Magento\Catalog\Model\Resource\Category\Tree
  */
 public function getTreeModel()
 {
     return $this->_categoryTreeFactory->create();
 }