Find products without categories

+1 vote
363 views
asked Sep 5, 2016 in Magento by Liam
Would you be able to advise the easiest way to generate a report of all products that do not belong to any categories. Will likely want to check this when I am finished with the import and development just in case I has missed some.

1 Answer

+1 vote
answered Sep 5, 2016 by Matt
<?php
require_once('app/Mage.php');
umask(0);
Mage::app('admin');
set_time_limit(0);

$i=0;
$sql = "select
    type_id,sku
 from catalog_product_entity a
 left join catalog_category_product cp on cp.`product_id` = a.entity_id
 left join catalog_product_relation cpr on cpr.child_id = a.entity_id
 where
       cp.product_id is null
   and cpr.parent_id is null
   and a.type_id = 'configurable'";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
//echo count($connection->fetchAll($sql));exit;

foreach ($connection->fetchAll($sql) as $arr_row) {
        $pid = $arr_row['sku'];
        $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$pid);
        if($product->getTypeId()!='configurable') continue;
        $i++;
        echo $i .") ". $product->getName() . " - " . $product->getSku() . "<br>";
}
?>

Related questions

0 votes
2 answers 306 views
0 votes
1 answer 323 views
0 votes
0 answers 278 views
+1 vote
1 answer 64 views
+1 vote
1 answer 135 views
0 votes
1 answer 272 views
...