Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Sort categories
- $root = Mage::getModel('catalog/category')->load(Mage::app()->getStore()->getRootCategoryId());
- $this->_sortChildren($root);
- }
- private function _sortChildren($parent)
- {
- Mage::log('Sorting '.$parent->getName(), null, 'acumen.log');
- if ($parent->hasChildren()) {
- $children = Mage::getModel('catalog/category')->getCollection()
- ->addFieldToFilter('entity_id', array('in'=>$parent->getChildrenCategories()))
- ->addAttributeToSort('acumen_category_sequence_number', 'ASC')
- ->load();
- // Sort children
- foreach ($children as $child) {
- if(isset($previousId)) $child->move($parent->getId(), $previousId);
- $previousId = $child->getId();
- }
- // Recurse
- foreach ($children as $child) {
- $this->_sortChildren($child);
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment