You need to overwrite the tree
and_nodeToArray
functions of Mage_Catalog_Model_Category_Api
:
/**
* Retrieve category tree
*
* @param int $parent
* @param string|int $store
* @return array
*/
public function tree($parentId = null, $store = null)
{
if (is_null($parentId) && !is_null($store)) {
$parentId = Mage::app()->getStore($this->_getStoreId($store))->getRootCategoryId();
} elseif (is_null($parentId)) {
$parentId = 1;
}
/* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
$tree = Mage::getResourceSingleton('catalog/category_tree')
->load();
$root = $tree->getNodeById($parentId);
if($root && $root->getId() == 1) {
$root->setName(Mage::helper('catalog')->__('Root'));
}
$collection = Mage::getModel('catalog/category')->getCollection()
->setStoreId($this->_getStoreId($store))
->addAttributeToSelect('name')
->addAttributeToSelect('is_active')
->addAttributeToSelect('image');
$tree->addCollectionData($collection, true);
return $this->_nodeToArray($root);
}
/**
* Convert node to array
*
* @param Varien_Data_Tree_Node $node
* @return array
*/
protected function _nodeToArray(Varien_Data_Tree_Node $node)
{
// Only basic category data
$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['image'] = $node->getImage();
$result['children'] = array();
foreach ($node->getChildren() as $child) {
$result['children'][] = $this->_nodeToArray($child);
}
return $result;
}
Following your needs, I think that retrieving the collection of categories and formating it to your needs would be more advised.