0

I am looking for a way to export all the products that are not assigned to any category. I know it can be done using XML, but I don't have enough knowledge in XML to create an Action so is there any easy export products that are not assigned to any category in CSV format?

2 Answers 2

4
 // First You need to get the collection of all product based on the category array having products.
       $collection = Mage::getModel('catalog/product')
                                 ->getCollection()
                                 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                                 ->addAttributeToSelect('*')
                                 ->addAttributeToFilter('category_id', array('eq' =>array(1,2,3,4)))
            ->getData();
       $cat_pro_id = array();
       foreach($collection as $prod_data){

       $cat_pro_id[] = $prod_data['id'];

   }
   //print_r($cat_pro_id); // here you got the all product id belongs to category

   $products = Mage::getModel('catalog/product')->getCollection()->getData();
       $pro_id = array();
       foreach($products as $product){
           $pro_id[] = $product['id'];
       }
 //print_r($pro_id);  // all product in store having product id
 $product_id_remain = $pro_id + $cat_pro_id ; // merging the two array get the id array of product which not belongs to category.
 $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' =>  $product_id_remain));
 // get the product collection based on prodcut id array filteration

//To save in csv file

$uri = 'main.csv';

 $csv = array( 
            'header' => array('products'),
            'rows' => $products,
        );

        $this->_h->CSV__write($uri, $csv);
0

Given you have a spreadsheet editor like Excel:

1) Export your entire product base

2) Open your CSV in excel

3) Sort the CSV by the Categories field, this will bring all the empty cells in this column to the top/bottom depending on how you sort.

4) Either copy all these products to a new excel for editing or remove the products that have categories and you will have a CSV of your category-less products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.