2013-02-06 67 views
0

我有一個問題,以獲得下面的代碼的子類別描述。需要顯示子類別的描述在magento

$category_model = Mage::getModel('catalog/category'); 
    $_category = $category_model->load(3); //loaded one category 
    $_subcategories = $_category->getChildrenCategories(); 

    foreach($_subcategories as $_subcategory): 
     echo $_subcategory->getName(); 
     echo $_subcategory->getDescription(); //I can't able to get description of the subcategory 
    endforeach; 

回答

1

得到的解決方案,我添加了我的問題的答案。很多優化的答案也將被讚賞。謝謝。

$category_model = Mage::getModel('catalog/category'); 
    $_category = $category_model->load(3); //loaded one category 
    $_subcategories = $_category->getChildrenCategories(); 

    foreach($_subcategories as $_subcategory): 
     echo $_subcategory->getName(); 
    //echo $_subcategory->getDescription(); //I can't able to get description of the subcategory 
    //Added to make as current category 
     $cur_category=Mage::getModel('catalog/category')->load($_subcategory->getId()); 
     $layer = Mage::getSingleton('catalog/layer'); 
     $layer->setCurrentCategory($cur_category); 
     echo $this->getCurrentCategory()->getDescription(); 

endforeach; 
0

我不是100%肯定你的努力做到,但嘗試

$category_model = Mage::getModel('catalog/category'); 
$_category = $category_model->load(3); //loaded one category 
$_subcategories = $_category->getChildrenCategories(); 

foreach($_subcategories as $_subcategory): 
    $cur_category=Mage::getModel('catalog/category')->load($_subcategory->getId()); 
    echo $cur_category->getName(); 
    echo $cur_category->getDescription(); 
endforeach; 
相關問題