Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created September 18, 2013 01:00
Show Gist options
  • Select an option

  • Save ryaan-anthony/6603022 to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/6603022 to your computer and use it in GitHub Desktop.
protected function _initCategories()
{
$collection = Mage::getResourceModel('catalog/category_collection')->addNameToResult();
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
foreach ($collection as $category) {
$structure = preg_split('#/+#', $category->getPath());
$pathSize = count($structure);
if ($pathSize > 1) {
$path = array();
for ($i = 1; $i < $pathSize; $i++) {
$path[] = $collection->getItemById($structure[$i])->getName();
}
$this->_rootCategories[$category->getId()] = array_shift($path);
if ($pathSize > 2) {
$this->_categories[$category->getId()] = implode('/', $path);
}
}
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment