如何在magento中加载多个类别ID?

时间:2015-07-15 04:51:05

标签: magento magento-1.9

您好我想在magento中加载多个类别ID,我在此使用但它只获取第一类子类别而不是其他类别。

$category = $model->load(79,80,91);  

3 个答案:

答案 0 :(得分:3)

您可以使用:

$categories = array(1,2,3);
$category = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('entity_id', array('in'=>$categories));
foreach($category as $categorys) {
//or do Somthing
}

答案 1 :(得分:1)

你必须使用集合而不是加载

  $collection = Mage::getModel('catalog/category')->getCollection()
                ->setStoreId(Mage::app()->getStore()->getId())
                ->addAttributeToSelect('name')
                ->addIdFilter(array(79,80,91))
                ->addAttributeToFilter('is_active', 1)//get only active categories if you want
                ->addAttributeToSort('position', 'desc'); //sort by position

然后你可以使用loop throw

foreach($collection as $category) {
    echo $category->getName()
}

希望这对你有用。

答案 2 :(得分:1)

你可以使用它,

$categories = array(10,13);
$_category = Mage::getModel('catalog/category');
$cats = $_category->getCollection()->addAttributeToFilter('entity_id', array('in'=>$categories));

foreach($cats as $cat) { 

    Zend_Debug::dump($cat);
    //or
    // do Somthing 
}