2010-04-02 34 views
0

這是我猜想的非常基本的magento問題。 我想先獲取所有商店類別,然後循環查看其子類別和產品,並類似地繼續到最後一個子類別。獲取所有的分類在外部頁面

我將在頁面頂部聲明Mage :: app()的外部頁面中使用它。我不知道Magento API(如果它們被稱爲)用來獲得這個功能。

請記住,我沒有在任何模板中使用這個,所以像getCurrentCategory()這樣的東西不會在這裏工作,我猜。

請指導是否有任何好的資源來搜索magento和API的特定功能來實現它,或者我註定要通過他們的phpdoc來了解方法列表。

在這裏的任何幫助將不勝感激, 謝謝。

回答

0

以下內容應該可以幫助你做你想做的事。從我的簡短介紹看來,Magento似乎並​​沒有嚴格按照類別/子類別的方式來考慮事情。相反,有一些類別,有些類別有父母,有些有孩子,有的有兩個。

//get a collection of all the categories 
Mage::app($mageRunCode, $mageRunType); 
//... 

//get a collection of all the categories 
$categories = Mage::getModel('catalog/category') 
->getCollection() 
->addAttributeToSelect('*');  

foreach($categories as $category) 
{ 
    //get an array of parent ids for this category 
    $array = $category->getParentIds(); 

    //get an array of children ids 
    $children = explode(',',$category->getChildren()); 

    //get a list of all the products in a category 
    $products = $category->getProductCollection(); 

} 

//pull collection of categories with a parent whose id is 13 
$categories = Mage::getModel('catalog/category') 
->getCollection() 
->addFieldToFilter('parent_id','13')  
->addAttributeToSelect('*');