Ejemplo n.º 1
0
 /**
  * @param \Magento\Framework\Data\Tree\Node $node
  * @param int $depth
  * @param int $currentLevel
  * @return \Magento\Catalog\Service\V1\Data\Eav\Category\Tree[]
  */
 public function getTree($node, $depth = null, $currentLevel = 0)
 {
     $builder = $this->treeBuilderFactory->create();
     $builder->setId($node->getId())->setParentId($node->getParentId())->setName($node->getName())->setPosition($node->getPosition())->setLevel($node->getLevel())->setActive($node->getIsActive())->setProductCount($node->getProductCount())->setChildren([]);
     if ($node->hasChildren()) {
         $children = array();
         foreach ($node->getChildren() as $child) {
             if (!is_null($depth) && $depth <= $currentLevel) {
                 break;
             }
             $children[] = $this->getTree($child, $depth, $currentLevel + 1);
         }
         $builder->setChildren($children);
     }
     return $builder->create();
 }