我有代码可以获得某个类别的子类别。
$parent = $category_model->load($current_category->parent_id);
$_categories = explode(',',$parent->getChildren());
但它似乎没有保留子类别在管理界面中的顺序。
我尝试使用->setOrder('position', 'ASC')
但似乎无法访问该方法。
任何人都知道如何设置上述代码的顺序?
答案 0 :(得分:0)
我设法以不同的方式做到这一点。之前,我获得了一系列类别ID,循环遍历它们并每次加载一个类别。这意味着我不能像普通的收藏品一样订购它们。因此,我只是将所有ID抛出到一个集合中,以便一次又一次地获取所有ID。
$category_model = Mage::getModel('catalog/category');
$current_category = Mage::registry('current_category');
$parent = $category_model->load($current_category->parent_id);
$_categoriesArray = explode(',',$parent->getChildren());
$_categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('entity_id', array('in' => $_categoriesArray))
->addAttributeToSelect('*')
->setOrder('position', 'ASC');