我需要列出類別內的所有產品。在Magento中,您不需要爲產品指定類別,因此我想列出所有不屬於某個類別的產品。Magento列出不屬於某個類別的產品
這是我試過,但它給了我一個錯誤:
$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();
}
看看@ http://stackoverflow.com/questions/9567729/magento-find -orphan-products或http://stackoverflow.com/questions/3717664/magento-get-a-list-of-products-that-are-not-related-to-any-category –