Magento列出不在类别中的产品 [英] Magento list products that arent in a category
本文介绍了Magento列出不在类别中的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要列出类别中的所有产品.在Magento中,您不需要为产品指定类别,因此我想列出所有不属于该类别的产品.
I need to list all products that are inside a category. In Magento, you don't need to specify a category for a product, so i want to list all those products that don't belong to a category.
这是我尝试过的方法,但它给了我一个错误:
This is what i tried but it gives me an error:
$productCollection = Mage::getModel('catalog/product')->getCollection();
foreach($productCollection as $_product){
$productId = $_product->getId();
$product = Mage::getModel('catalog/product')->load($productId);
$currentCatIds = $_product->getCategoryIds();
$categoryCollection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('name')
->addAttributeToSelect('url')
->addAttributeToFilter('entity_id', $currentCatIds)
->addIsActiveFilter();
$i = 0;
foreach($categoryCollection as $cat){
$i++;
//echo $cat->getName().' '.$cat->getUrl();
}
if($i) echo $product->getName();
}
推荐答案
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('category_ids','');
这篇关于Magento列出不在类别中的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文