private function nodeToArray(Varien_Data_Tree_Node $node, $mediaUrl, $baseUrl) { $result = array(); $thumbnail = ''; try { $thumbImg = $node->getThumbnail(); if ($thumbImg != null) { $thumbnail = $mediaUrl . 'catalog/category/' . $node->getThumbnail(); } } catch (Exception $e) { } $result['category_id'] = $node->getId(); $result['image'] = $mediaUrl . 'catalog/category/' . $node->getImage(); $result['thumbnail'] = $thumbnail; $result['description'] = strip_tags($node->getDescription()); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['children'] = array(); if (method_exists('Mage', 'getEdition') && Mage::getEdition() == Mage::EDITION_COMMUNITY) { $result['url_path'] = $baseUrl . $node->getData('url_path'); } else { $category = Mage::getModel('catalog/category')->load($node->getId()); $result['url_path'] = $category->getUrl(); } foreach ($node->getChildren() as $child) { $result['children'][] = $this->nodeToArray($child, $mediaUrl, $baseUrl); } return $result; }
function nodeToArray(Varien_Data_Tree_Node $node) { $result = array(); $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->nodeToArray($child); } return $result; }
private function nodeToArray(Varien_Data_Tree_Node $node) { $result = array(); $category = Mage::getModel('catalog/category')->load($node->getId()); if ($category->getAvailableForSupplier() == 1) { $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); } $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->nodeToArray($child); } return $result; }
/** * Convert node to array with path information. * Path information skips the 'Root Catalog' (level=0) and 'Default Category' (level=1) levels. * * @param Varien_Data_Tree_Node $node * @return array */ protected function _nodeToArrayPath(Varien_Data_Tree_Node $node, $parentPath) { // Only basic category data $categories = array(); $category = array(); $category['category_id'] = $node->getId(); $category['parent_id'] = $node->getParentId(); $category['name'] = $node->getName(); $category['path'] = !empty($parentPath) && $node->getLevel() > 2 ? $parentPath . '/' . $node->getName() : $node->getName(); $category['is_active'] = $node->getIsActive(); $category['position'] = $node->getPosition(); $category['level'] = $node->getLevel(); $categories[] = $category; foreach ($node->getChildren() as $child) { $children = $this->_nodeToArrayPath($child, $category['path']); $categories = array_merge($categories, $children); } return $categories; }
/** * Convert categories tree to array recursively * * @param Varien_Data_Tree_Node $node * @return array */ protected function _getNodesArray($node) { $result = array('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 (is_array($this->_allowedCategoryIds) && !in_array($result['id'], $this->_allowedCategoryIds)) { $result['disabled'] = true; } if ($node->hasChildren()) { $result['children'] = array(); 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; }
protected function _nodeToArray(Varien_Data_Tree_Node $node) { if (empty($node)) { return array(); } $result = $node->debug(); $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['is_anchor'] = $node->getIsAnchor(); $result['url_key'] = $node->getUrlKey(); $result['url'] = $node->getRequestPath(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); $result['products'] = $node->getProducts(); $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->_nodeToArray($child); } return $result; }