Created
October 24, 2014 10:08
-
-
Save arioch1984/67cc0e7a6deb916439d7 to your computer and use it in GitHub Desktop.
get an array of all categories with details in Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$categories = Mage::getModel('catalog/category')->getCollection() | |
->addAttributeToSelect('id') | |
->addAttributeToSelect('name') | |
->addAttributeToSelect('url_key') | |
->addAttributeToSelect('url') | |
->addAttributeToFilter('level',2) | |
->addAttributeToSelect('is_active'); | |
foreach ($categories as $category) | |
{ | |
if ($category->getIsActive()) { // Only pull Active categories | |
$entity_id = $category->getId(); | |
$name = $category->getName(); | |
$url_key = $category->getUrlKey(); | |
$url_path = $category->getUrl(); | |
} | |
} | |
//OR | |
$category = Mage::getModel('catalog/category'); | |
$tree = $category->getTreeModel(); | |
$tree->load(); | |
$ids = $tree->getCollection()->getAllIds(); | |
if ($ids){ | |
foreach ($ids as $id){ | |
$cat = Mage::getModel('catalog/category'); | |
$cat->load($id); | |
$entity_id = $cat->getId(); | |
$name = $cat->getName(); | |
$url_key = $cat->getUrlKey(); | |
$url_path = $cat->getUrlPath(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment