Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. // Sort categories
  4. $root = Mage::getModel('catalog/category')->load(Mage::app()->getStore()->getRootCategoryId());
  5. $this->_sortChildren($root);
  6. }
  7.  
  8. private function _sortChildren($parent)
  9. {
  10. Mage::log('Sorting '.$parent->getName(), null, 'acumen.log');
  11.  
  12. if ($parent->hasChildren()) {
  13.  
  14. $children = Mage::getModel('catalog/category')->getCollection()
  15. ->addFieldToFilter('entity_id', array('in'=>$parent->getChildrenCategories()))
  16. ->addAttributeToSort('acumen_category_sequence_number', 'ASC')
  17. ->load();
  18.  
  19. // Sort children
  20. foreach ($children as $child) {
  21. if(isset($previousId)) $child->move($parent->getId(), $previousId);
  22. $previousId = $child->getId();
  23. }
  24.  
  25. // Recurse
  26. foreach ($children as $child) {
  27. $this->_sortChildren($child);
  28. }
  29. }
  30. }
  31.  
  32. ?>
Add Comment
Please, Sign In to add comment