Friday, 28 February 2014

Change sort order of Magento subcategories

Try calling getChildrenCategories this will take into account the position of each category:
$loadCategory->getChildrenCategories()
EDITED
Unlike getChildren which returns a string of all category ids returns an array of Mage_Catalog_Model_Category so your code will need to be changed to take this into account.
From your code snippet above the following change should work. Note the call to getChildrenCategories() and the change in the foreach loop as each item should be a category object.

<?php
$currentCat = Mage::registry('current_category');

if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
    // current category is a toplevel category
    $loadCategory = $currentCat;
}
else
{
    // current category is a sub-(or subsub-, etc...)category of a toplevel category
    // load the parent category of the current category
    $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = $loadCategory->getChildrenCategories();

foreach ( $subCategories as $subCategory )
{
    if($subCategory->getIsActive())
    {
        echo '<a href="'.$subCategory->getURL().'">'.$subCategory->getName().'</a>';
    }
}
?> 

No comments:

Post a Comment