0

我有代码可以获取一个类别的子类别。

$parent = $category_model->load($current_category->parent_id);
$_categories = explode(',',$parent->getChildren());

但它似乎并没有保持子类别在管理界面中的放置顺序。

我尝试使用->setOrder('position', 'ASC'),但似乎无法访问该方法。

有人知道如何设置上述代码的顺序吗?

4

1 回答 1

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');
于 2012-10-16T09:19:38.193 回答