2013-09-03 1 views
1

id = 5 & 37 인 주 범주 (상위 범주)가 있습니다. 하위 범주를 수집하려고합니다. 어떻게해야합니까?두 부모 범주의 하위 범주를 얻는 방법

$catid = array(5,37); 


$_category = Mage::getModel('catalog/category')->load(5); 
$_subcategories1 = $_category->getChildrenCategories(); 
$_category = Mage::getModel('catalog/category')->load(37); 
$_subcategories2 = $_category->getChildrenCategories(); 

내가 두 범주 ID 아동 범주가 컬렉션을 원하는 (5,37)

여기에 내가 하나 개의 컬렉션 카테고리의 두 집합을 병합 당신에게 하나의 예를 제공하고

답변

2

당신은 하나를 선택할 것을 얻을 수 있습니다 : 그 작업 @Marius

$subcategories = Mage::getModel('catalog/category') 
    ->setStoreId(Mage::app()->getStore()->getId()) 
    ->getCollection() 
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter('parent_id', array(5, 37)) 
    ->setOrder('parent_id', 'ASC');//if you want them somehow grouped by parent_id 
foreach ($subcategories as $category){ 
    //do something with $category 
} 
+0

고맙습니다. – shivam

0

$storeId = Mage::app()->getStore()->getId(); 
    $categoryOneId = 5; 
    $categoryTwoId = 37; 

    $categoryOne = Mage::getModel('catalog/category')->load($categoryOneId); 
    $categoryTwo = Mage::getModel('catalog/category')->load($categoryTwoId); 

    $collectionOne = Mage::getModel('catalog/product')->getCollection() 
     ->setStoreId($storeId) 
     ->addCategoryFilter($categoryOne); 

    $collectionTwo = Mage::getModel('catalog/product')->getCollection() 
     ->setStoreId($storeId) 
     ->addCategoryFilter($categoryTwo); 

    $merged_ids = array_merge($collectionOne->getAllIds(), $collectionTwo->getAllIds()); 

    $mergedCollection = Mage::getModel('catalog/product')->getCollection() 
     ->addFieldToFilter('entity_id', $merged_ids); 

희망이 도움이 될 것입니다.

관련 문제