Tuesday, July 19, 2011

Get root categories in magento

$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToSelect('name')
    ->addPathFilter('^1/[0-9]+$')
    ->load();

$options = array();
foreach ($collection as $category) {
    $options[] = array(
       'label' => $category->getName(),
       'value' => $category->getId()
    );
}
print_r($options); 

No comments:

Post a Comment