Is there any way to assign products to a category that are not assigned to any category? I have around 1000 products that are not assigned to any category so I would like to assign them to one single category.
1 Answer
Try this.
- Write an external script to achieve this.
In the script put the following code and make sure to put your category id instead what there is.
$category_id = 8; // Get all the product collection. $collection = Mage::getModel('catalog/product')->getCollection(); foreach($collection as $product) { // Get categories of product. $cats = $product->getCategoryIds(); // If this product doesn't have categories. if(count($cats) == 0) { // Set the category id and save. $product->setCategoryIds(array($category_id)); $product->save(); } }