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?

  • Can you please specify Magento version ? – Abdul Pathan Jun 24 at 10:31
  • explain briefly what you exactly doing ?? – Rk Rathod Jun 24 at 10:31
  • Magento 1 ver. 1.9.3.7 – joe willmott Jun 24 at 10:32
  • I am trying to delete all products which are not in active categories – joe willmott Jun 24 at 10:32
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.

  • 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? – joe willmott Jun 24 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 – Shoaib Munir Jun 24 at 10:52
  • how would you do a dry run? i now have the root folder – joe willmott Jul 9 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 – Shoaib Munir Jul 9 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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