Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Magento中,如何按照您在管理区域中看到的顺序获取类别列表?_Magento - Fatal编程技术网

在Magento中,如何按照您在管理区域中看到的顺序获取类别列表?

在Magento中,如何按照您在管理区域中看到的顺序获取类别列表?,magento,Magento,我可以使用以下代码获取特定类别的子类别列表: public function displaycats($data, $begin,$end, $catid){ $currentCat = Mage::getModel('catalog/category')->load($data[0]); $children = explode(",",$currentCat->getChildren()); foreach ($children as $child) {

我可以使用以下代码获取特定类别的子类别列表:

public function displaycats($data, $begin,$end, $catid){
    $currentCat = Mage::getModel('catalog/category')->load($data[0]);
    $children = explode(",",$currentCat->getChildren());

    foreach ($children as $child) {
    $cot++;
    $subCat = Mage::getModel('catalog/category')->load($child);

        if ($cot >= $begin && $cot <= $end){
            echo '<a href="'.$subCat->getUrl().'?stockable=786">'.$subCat->getName()."</a><br>";
        }
    }
    return;
}
public函数displaycats($data、$begin、$end、$catid){
$currentCat=Mage::getModel('catalog/category')->load($data[0]);
$children=explode(“,”,$currentCat->getChildren());
foreach($childrenas$child){
$cot++;
$subCat=Mage::getModel('catalog/category')->load($child);

如果($cot>=$begin&&$cot请查看getCategories。它有一个排序参数以及一个作为集合对象返回的选项,无需再次从数据库中加载每个类别

/**
*检索类别
*
*@param integer$parent
*@param integer$recursionLevel
*@param boolean |字符串$sorted
*@param boolean$asCollection
*@param boolean$toLoad
*@return Varien_Data_Tree_Node_Collection|Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection|
*/
公共函数getCategories($parent、$recursionLevel=0、$sorted=false、$asCollection=false、$toLoad=true)

`

改为查看getCategories。它有一个排序参数以及一个作为集合对象返回的选项,无需再次从数据库中加载每个类别

/**
*检索类别
*
*@param integer$parent
*@param integer$recursionLevel
*@param boolean |字符串$sorted
*@param boolean$asCollection
*@param boolean$toLoad
*@return Varien_Data_Tree_Node_Collection|Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection|
*/
公共函数getCategories($parent、$recursionLevel=0、$sorted=false、$asCollection=false、$toLoad=true)

`

我喜欢@Joe Constant的答案,但当我尝试它时,我只在获取第一级子类别时遇到了问题,即使
$recursionLevel
设置为
0
。作为一种解决方法,我编写了这个函数(将它放在需要排序的子集合的(本地版本)块中):

然后,您可以在集合中进行迭代,并执行以下所需操作:

foreach (getChildrenCollection($parentCategoryId) as $child) {
  Zend_Debug::dump($child->getData());
}

希望这能有所帮助。

我喜欢@Joe Constant的答案,但当我尝试它时,我在获取第一级子类别时遇到了困难,即使
$recursionLevel
设置为
0
。作为一种解决方法,我编写了这个函数(将它放在需要排序的子集合的(本地版本)块中):

    $helper     = Mage::helper('catalog/category');
    $_categories     = $helper->getStoreCategories('path', true, FALSE);
然后,您可以在集合中进行迭代,并执行以下所需操作:

foreach (getChildrenCollection($parentCategoryId) as $child) {
  Zend_Debug::dump($child->getData());
}
希望有帮助

    $helper     = Mage::helper('catalog/category');
    $_categories     = $helper->getStoreCategories('path', true, FALSE);
如果要以以下格式显示类别

第一类

---第1a小类

------第1aa子类

---第1b子类

第2类

---第2a小类

---子类别2b

    foreach($_categories as $category){
        $level = $category['level'] - 2;
        $pad = str_repeat("---", ($level > 0) ? $level : 0);

        echo $pad . ' ' . $cat['name']);
        echo '<br/>';
    }

    return $categories;
foreach($\类别为$category){
$level=$category['level']-2;
$pad=str_repeat(“--”,($level>0)?$level:0);
echo$pad.'.$cat['name']);
回声“
”; } 返回$categories;
如果要以以下格式显示类别

第一类

---第1a小类

------第1aa子类

---第1b子类

第2类

---第2a小类

---子类别2b

    foreach($_categories as $category){
        $level = $category['level'] - 2;
        $pad = str_repeat("---", ($level > 0) ? $level : 0);

        echo $pad . ' ' . $cat['name']);
        echo '<br/>';
    }

    return $categories;
foreach($\类别为$category){
$level=$category['level']-2;
$pad=str_repeat(“--”,($level>0)?$level:0);
echo$pad.'.$cat['name']);
回声“
”; } 返回$categories;
我刚刚写了一些类似的东西来获得类别列表(按parentId),就像在admin中一样:

$subCats = array();
$children = Mage::getModel('catalog/category')->getCategories($parentId, 1, true, true);
foreach ($children as $category)
{
    $subCats[$category->getPosition()] = $category->getId();
}
ksort($subCats);

我只是写了一些类似这样的东西来获得类别列表(按parentId),就像在admin中一样排序:

$subCats = array();
$children = Mage::getModel('catalog/category')->getCategories($parentId, 1, true, true);
foreach ($children as $category)
{
    $subCats[$category->getPosition()] = $category->getId();
}
ksort($subCats);