1

How to get root category details like name, id, URL, imageurl, description. I write some code but I don't get the description and image url. My code is

$_categories = Mage::getModel('catalog/category')->getCollection()
                 ->addAttributeToSelect('name')
                 ->addAttributeToSelect('is_active')
                 ->addUrlRewriteToResult();


foreach($_categories as $_category): 
$catUrl = $_category->getUrl($_category);
$catName = $_category->getName($_category);
$catId = $_category->getId($_category);
$catDescription = $_category->getDescription();
$catImageurl = $_category->getImageUrl();
endforeach; 
1
  • first print_r($_category) and see which data you are getting there.
    – Piyush
    Feb 29, 2016 at 10:57

2 Answers 2

0

Try This code

     <?php

        $category = Mage::getModel('catalog/category')->load(2);
        $subCategory=($category->getResource()->getChildren($category, true));
         foreach ($subCategory as $categoryID)
         {
            $sCategory = Mage::getModel('catalog/category')->load($categoryID);
            echo $sCategory->getUrlKey();
            echo $sCategory->getName();
            echo $sCategory->getImageUrl();

         }

        ?>
0
0

You have to add the attributes you need (* for all):

->addAtrtibuteToSelect('*')
1
  • I got the error "undefined method Mage_Catalog_Model_Resource_Category_Collection::addAtrtibuteToSelect() " when i put this Feb 29, 2016 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.