Created
April 27, 2015 07:55
-
-
Save michaelhoang/962584cd4e5f1c210199 to your computer and use it in GitHub Desktop.
Magento Category
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
public function categoryTravel($category, $level) | |
{ | |
$result = new Varien_Data_Collection; | |
if (is_numeric($category)) { | |
$category = Mage::getModel('catalog/category')->load($category); | |
} | |
$this->_categoryTravel($result, $level, $category); | |
return $result; | |
} | |
protected function _categoryTravel($result, $level, $category) | |
{ | |
$result->addItem($category); | |
if ($level === null || $category->getLevel() < $level) { | |
$categoryChildren = $category->getChildrenCategories(); | |
foreach ($categoryChildren as $_category) { | |
$this->_categoryTravel($result, $level, $_category); | |
} | |
} | |
} | |
// Use function | |
categoryTravel(5, 6); // Category id = 5, level = 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment