4

our site has over 90,000 products which need to be deleted and are not in categories, but the products in the categories we want to keep, how do i solve this?

4
  • Can you please specify Magento version ? Commented Jun 24, 2019 at 10:31
  • explain briefly what you exactly doing ?? Commented Jun 24, 2019 at 10:31
  • Magento 1 ver. 1.9.3.7 Commented Jun 24, 2019 at 10:32
  • I am trying to delete all products which are not in active categories Commented Jun 24, 2019 at 10:32

1 Answer 1

2

Create a custom script on root directory

delete_products.php

code would be this:

<?php
include_once __DIR__ . '/app/Mage.php';
Mage::app('admin');


//Getting all prdoucts collection
$collection = Mage::getResourceModel('productslider/product_collection')
                ->addAttributeToSelect('*');


foreach($collection as $prod){
    $prodId = $prod->getId();
    $_product = Mage::getModel('catalog/product')->load($prodId);
    $categoryIds = $_product->getCategoryIds(); 
    if(count($categoryIds) == 0){
        //Delete prdouct
        //$_product->delete();
        echo $prodId;
    }
}

I have used echo and commented delete function. You first need to dry run this script, and if it is giving you the products that need to be deleted, then uncomment delete code.

4
  • The main problem i also have is that i do not know who hosts the site and where any of the root files i need are. My compnay have set me the task to sort it out with no info, is there a way to see where the Cpanel is? Commented Jun 24, 2019 at 10:45
  • I have no idea which hosting you are using. You need code access to do this task, otherwise this is nearly impossible Commented Jun 24, 2019 at 10:52
  • how would you do a dry run? i now have the root folder Commented Jul 9, 2019 at 10:22
  • Just execute the file and check what it is printing, if product id's are fine, then remove comment from code and delete products Commented Jul 9, 2019 at 10:29

Your Answer

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

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