Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

getChildrenCategories not working in function
 
Tonino
Jr. Member
 
Total Posts:  12
Joined:  2009-04-27
 

I’m modifying a code containing interface calls to Magento (for calling Magento from external php code).
Base code is very simple:

function myCall ($category{

                $cModel 
Mage::getModel 'catalog/category' );

                
$cModel->load($category);

                
$children $cModel->getChildrenCategories ();
                
$hasChildren $children && $children->count ();

After ->load, I can get category name and other datas, but no children at all (I know they exist).
Any hint? Any other basic function I could use?

Thanks,

Tonino

 
Magento Community Magento Community
Magento Community
Magento Community
 
datensurfer
Sr. Member
 
Total Posts:  103
Joined:  2009-07-15
 

I have the same problem, no solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
oe_eduardo
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2011-02-03
London
 

to get the subcategories nicely thanks to some benjamin

sonassi.com/knowledge-base/quick-script-to-export-categories-with-ids/comment-page-1/#comment-71192

<?php

require_once ‘/app\Mage.php’;
Mage::app();

$category = Mage::getModel ( ‘catalog/category’ );
$tree = $category->getTreeModel ();
$tree->load ();

$nodes = $tree->getNodes();

if ($nodes) {
$file = “/var/import/cats.csv”;
file_put_contents($file,"\"catId\”,\"catName\”,\"catPath\"\n");
echo “\"catId\”,\"catName\”,\"catPath\"\n";

foreach ( $nodes as $node ) {

$id = $node->getId();
$name = $category->load($id)->getName();

$path = ‘’;
$parents = $node->getPath();
foreach ($parents as $i=>$parent) {
$parent_id = $parent->getId();
$parent_name = $category->load($parent_id)->getName();
$path = $parent_name . ($i?’/’:’’) . $path;
}

$string = ‘“‘. $node->getId() . ‘“,"’. $name . ‘“,"’. $path . “\"\n";
file_put_contents($file,$string,FILE_APPEND);
echo “$string\n”;
}
}

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top