Created
June 1, 2015 21:55
-
-
Save justindocanto/35cd134a15246e1f40ac to your computer and use it in GitHub Desktop.
Magento - Return id, name & url of product categories
This file contains 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 | |
// Get Magento categories | |
function get_magento_categories() { | |
require_once 'app/Mage.php'; | |
Mage::app(); | |
$category = Mage::getModel('catalog/category'); | |
$tree = $category->getTreeModel(); | |
$tree->load(); | |
$ids = $tree->getCollection()->getAllIds(); | |
$categories = array(); | |
if ($ids){ | |
$i=1; | |
foreach ($ids as $id){ | |
$cat = Mage::getModel('catalog/category'); | |
$cat->load($id); | |
if($cat->getName() !== "Root Catalog" && $cat->getName() !== "Store") { // My lazy way of hiding root categories | |
$categories[$i]['id'] = $id; | |
$categories[$i]['name'] = $cat->getName(); | |
$categories[$i]['url'] = $cat->getUrl(); | |
$i++; | |
} | |
} | |
} | |
return $categories; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment