示例#1
0
 /**
  * @param \Magento\Catalog\Model\Category\TreeFactory $categoryTreeFactory
  * @param \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryResourceTreeFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
  * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
  */
 public function __construct(\Magento\Catalog\Model\Category\TreeFactory $categoryTreeFactory, \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryResourceTreeFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory)
 {
     $this->categoryTree = $categoryTreeFactory->create(['categoryTree' => $categoryResourceTreeFactory->create(), 'categoryCollection' => $categoryCollectionFactory->create()]);
     $this->eavConfig = $eavConfig;
     $this->attributeCollectionFactory = $attributeCollectionFactory;
     $this->attrOptionCollectionFactory = $attrOptionCollectionFactory;
     $this->productCollection = $productCollectionFactory->create();
 }
示例#2
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\ResourceModel\Category\Collection
  */
 public function getCategories($parent, $recursionLevel = 0, $sorted = false, $asCollection = false, $toLoad = true)
 {
     $tree = $this->_categoryTreeFactory->create();
     /* @var $tree \Magento\Catalog\Model\ResourceModel\Category\Tree */
     $nodes = $tree->loadNode($parent)->loadChildren($recursionLevel)->getChildren();
     $tree->addCollectionData(null, $sorted, $parent, $toLoad, true);
     if ($asCollection) {
         return $tree->getCollection();
     }
     return $nodes;
 }
示例#3
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->getDefaultStoreView()->getRootCategoryId();
         }
         $tree = $this->resourceCategoryTreeFactory->create();
         $node = $tree->loadNode($rootNode)->loadChildren();
         $tree->addCollectionData(null, false, $rootNode);
         $this->categoryTree = $node;
     }
     return $this->categoryTree;
 }
 /**
  * Retrieve category tree model
  *
  * @return \Magento\Catalog\Model\ResourceModel\Category\Tree
  */
 public function getTreeModel()
 {
     return $this->_categoryTreeFactory->create();
 }