2010-04-02 7 views
0

이것은 매우 기본적인 자홍색 질문입니다. 먼저 모든 상점 카테고리를 가져온 다음 하위 카테고리 및 제품을 가져 오기 위해 반복하여 마지막 하위 카테고리까지 계속 진행합니다.외부 페이지의 모든 카테고리 얻기

페이지 상단에 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('*');   
관련 문제