Last active
August 29, 2015 14:05
-
-
Save code-poel/55a364aa8832600bece2 to your computer and use it in GitHub Desktop.
Get all active category names.
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 | |
public function getAllCategoryNames() | |
{ | |
$names = array(); | |
// Build out a category collection and add the name attribute to the select. | |
$model = Mage::getModel('catalog/category'); | |
$collection = $model->getCollection(); | |
$collection->addAttributeToSelect('name'); | |
// Make sure the categories are actually active. | |
$collection->addIsActiveFilter(); | |
// Start at the root. | |
$collection->addLevelFilter(1); | |
// Order by name (obviously, optional). | |
$collection->addOrderField('name'); | |
foreach ($collection as $category) { | |
/* @var $category Mage_Catalog_Model_Category */ | |
$names[] = $category->getName(); | |
} | |
return $names; | |
} | |
public function getAllCategoryNamesRespectDepth() | |
{ | |
$names = array(); | |
$helper = Mage::helper('catalog/category'); | |
// Watch out, this method respects the depth limit set in the | |
// 'catalog/navigation/max_depth' setting in admin. | |
$collection = $helper->getStoreCategories('name', true, false); | |
foreach ($collection as $category) { | |
/* @var $category Mage_Catalog_Model_Category */ | |
$names[] = $category->getName(); | |
} | |
return $names; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment