2012-01-02 4 views
5

Magento ver1.6.1을 사용하고 있습니다. 상점의 루트 카테고리를 가져와야합니다. 나는 좋은 아이디어/코드를 얻지 못해서 Google에서 검색합니다. 상점의 루트 카테고리를 얻는 방법을 알려주십시오.매장 루트 카테고리 찾기

Mage::app()->getStore()->getRootCategoryId() 

위의 코드는 기본 루트 카테고리를 제공하지만 저장소 생성 중에 선택하는 카테고리 ID가 필요합니다.

답변

14

는 당신이 시도 : 내 플랫폼은 멀티 스토어 뷰에 구성된으로

Mage::app()->getStore($storeId)->getRootCategoryId(); 
+2

확장에 대한 설치/업그레이드 스크립트에서 저장소 데이터를 가져 오는 경우 먼저 Mage :: init()을 실행해야합니다. 그렇지 않으면 저장소 개체가 채워지지 않습니다. –

0

내 자신의 도움을 작성하고 모든 의미에서 내가 올바른 루트 카테고리 ID를 받고되지 않았습니다. 나는 아래의 모든 솔루션 :

솔 1 :

Mage::app()->getStore($storeId)->getRootCategoryId(); //The result was ID: 2 

솔 2 :

Mage::app()->getStore()->getRootCategoryId(); //The result was ID: 2 

솔 3 만 근무하고 ID: 1가 반환

$store = Mage::getModel('core/store')->load(Mage_Core_Model_App::DISTRO_STORE_ID); 
$categoryId = $store->getRootCategoryId();// The result was again ID: 2 

방법 아래 주어진 및 here

에서 찍은
public function getRootCategoryId() 
{ 
    $categories = Mage::getModel('catalog/category')->getCollection(); 
    $categIds = $categories->getAllIds(); 
    asort($categIds); 
    foreach ($categIds as $k => $catId) 
    { 
     $category = Mage::getModel('catalog/category')->load($catId); 
     if ($category->name) 
     { 
      return $catId; 
     } 
    } 
}