Ejemplo n.º 1
0
 /**
  * Convert categories tree to array recursively
  *
  * @param  \Magento\Framework\Data\Tree\Node $node
  * @return array
  */
 protected function _getNodesArray($node)
 {
     $result = ['id' => (int) $node->getId(), 'parent_id' => (int) $node->getParentId(), 'children_count' => (int) $node->getChildrenCount(), 'is_active' => (bool) $node->getIsActive(), 'name' => $node->getName(), 'level' => (int) $node->getLevel(), 'product_count' => (int) $node->getProductCount()];
     if ($node->getParentId() == Category::TREE_ROOT_ID && !in_array($result['id'], $this->_allowedCategoryIds)) {
         $result['disabled'] = true;
     }
     if ($node->hasChildren()) {
         $result['children'] = [];
         foreach ($node->getChildren() as $childNode) {
             $result['children'][] = $this->_getNodesArray($childNode);
         }
     }
     $result['cls'] = ($result['is_active'] ? '' : 'no-') . 'active-category';
     $result['expanded'] = !empty($result['children']);
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param array|Node $node
  * @param int $level
  * @return array
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _getNodeJson($node, $level = 1)
 {
     $item = [];
     $item['text'] = $this->escapeHtml($node->getName());
     if ($this->_withProductCount) {
         $item['text'] .= ' (' . $node->getProductCount() . ')';
     }
     $item['id'] = $node->getId();
     $item['path'] = $node->getData('path');
     $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
     $item['allowDrop'] = false;
     $item['allowDrag'] = false;
     if (in_array($node->getId(), $this->getCategoryIds())) {
         $this->setExpandedPath($node->getData('path'));
         $item['checked'] = true;
     }
     if ($node->getLevel() < 2) {
         $this->setExpandedPath($node->getData('path'));
     }
     if ($node->hasChildren()) {
         $item['children'] = [];
         foreach ($node->getChildren() as $child) {
             $item['children'][] = $this->_getNodeJson($child, $level + 1);
         }
     }
     if (empty($item['children']) && (int) $node->getChildrenCount() > 0) {
         $item['children'] = [];
     }
     $item['expanded'] = in_array($node->getId(), $this->getExpandedPath());
     return $item;
 }