如果“类别”未激活,则返回产品

时间:2013-05-21 13:27:36

标签: magento

如果类别不活跃,如何让$cat->getProductCollection();返回产品

已经很长时间了。我无法让它发挥作用。

这就是我在做的事情。但没有运气

        private function _getCollection() {

    $category = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToFilter('is_active',array('eq'=>False))
    ->addAttributeToFilter('entity_id',array('eq'=>'61'))
    ->load();

        foreach($category as $cat){            

        $Prods = $cat->getProductCollection();                     
        $Prods->addWebsiteFilter();            
        $Prods->addAttributeToSelect('*');

        }


           return $Prods;
}

1 个答案:

答案 0 :(得分:0)

试试此代码

$cat = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('is_active', 1);

foreach ($cat as $category){
$cat_id = $category->getId();
$category = new Mage_Catalog_Model_Category();
$category->load($cat_id);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');

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

}