Export list of products that have no category in magento

To get the list products have no category we need to retrieve the product collection and then filter the result with category check , filtered result will make to export in csv format. 

<?php

ob_end_clean();

require_once('app/Mage.php');

umask(0);
Mage::app();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('entity_id') 
->addAttributeToSelect('sku') 
->addAttributeToSelect('name');
// We assume we need three fields to export in csv format productId,SKU and Product name.
 $num_fields = 3;
 $headers = array();
 $headers[] = "[Row]";
 
 $headers[] = 'ProductId';
 $headers[] = 'ProductName';
 $headers[] = 'ProductSku';
 
$current_date = date("y/m/d");
$filename = "productlist" . $current_date . ".csv";
 
// Open php output stream and write headers
$fp = fopen('php://output', 'w');
if ($fp) {
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename='.$filename);
    header('Pragma: no-cache');
    header('Expires: 0');
    echo "Products List that have no categorynn";
    // Write mysql headers to csv
    fputcsv($fp, $headers);
    $row_tally = 0;
   
   
foreach($collection as $product)  {              //list of all products
    
$cats = $product->getCategoryIds();
 
                                         // If this product doesn't have categories.
          if(count($cats) == 0) {
$row_tally = $row_tally + 1;
echo $row_tally.",";
$prodData = array($product->getData('entity_id'), $product->getData('sku'),
                                                  $product->getData('name'));
       fputcsv($fp, array_values($prodData));
      
               }
       }
 
 }
?>

 

0   0
Aditya Singh
profile Jennifer 31st March 2024

Wow, What an exceptional pronounce. i found this too much informatics. it’s miles what i used to be searching for for. i’d as soon as to area you that absorb keep sharing such kind of data.If realistic, thank you. buyers

Write a comment ...
Post comment
Cancel
profile 222 Aloha 5th July 2023

At the appointed time, one of our professional carpet cleaners will arrive at your residence or place of business, move any necessary furniture, and thoroughly clean your carpets. | austin commercial carpet cleaning

Write a comment ...
Post comment
Cancel
profile marget 1st June 2023

if you are a serious gamer who spends hours in front of your computer screen, then investing in a good quality ergonomic gaming chair is a must. The Best Ergonomic Gaming Chair is one of the best chairs in the market, offering maximum comfort and support to gamers. So, why wait? Get your Best Ergonomic Gaming Chair today and take your gaming experience to the next level! best bean bag chair for gaming 2023

Write a comment ...
Post comment
Cancel

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site