Jump to content

Massive product deleting


silvioscavone

Recommended Posts

Hello,

I ask help for an urgent problem:

I have to delete massively 100.000 products inside an id range.

I found a PHP script that should do the job in a past thread, but I’m not sure it works without any damage to the website and looks like it deletes all the products, not a specific range.

I have a good PHP background but I don’t have a deep knowledge of prestashop , so I don’t know how to do it properly.

If anyone can help, it would be appreciated.

Thank you very much in advance,

 

Silvio

 

 

 

 

Link to comment
Share on other sites

Your post raises many questions:

  - which script did you find?

 - is it PS 1.6 or 1.7? 1.7 has database constraints so it needs a different handling.

 - you write that your PHP is good but you don't mention your mysql knowledge. It doesn't seem hard to me to know whether a script deletes all products or a segment. And it doesn't seem hard to add a condition like "WHERE id_product>1000 AND id_product<2000" to every query..

Link to comment
Share on other sites

Hello,

thank you for your reply.

I found something on the following thread:

https://www.prestashop.com/forums/topic/609319-solved-delete-massive-products-from-database-10420-products/

I'm running PS 1.6

I have low MySQL knowledge but I understand simple queries.

You are definitely right, I think it won't be hard, just I need to know how to do it properly because I can't do any mistake.

I need something that does exactly what the BO "Massive action -> Delete" does when selecting products,

but I need it specifying a product id range.

 

Do you think the script in that thread could work and could I add the condition you mention somewhere ?

"WHERE id_product>1000 AND id_product<2000"

 

I thank you very much for your help,

 

Silvio

Link to comment
Share on other sites

Something like

$res = Db::getInstance()->executeS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE id_product > 100 AND product < 200 ORDER BY `id_product` DESC LIMIT 100 ');

 

Note that the script handles 100 products at a time due to the server timeout. That will be quite a few page refreshes for your 100,000 products....

Edited by musicmaster (see edit history)
Link to comment
Share on other sites

Well, how about make it in "proper" PHP way and create a simple module like. 
 

require_once(dirname(__FILE__).'/../../config/config.inc.php');

$products_to_delete = Db::getInstance()->executeS('
    SOME QUERY TO products_id You want to delete
');

foreach ($products_to_delete as $product_id) {
    $p = new Product($product_id);
	if (Validate::isLoadedObject($p)){
    	$p->delete();
		echo 'Deleted with ID:'.$product_id.' <br>';
	}
}

move this to some module folder and run it from browser. 

Be sure to check $products_to_delete with ddd($produts_to_delete) to see if You query contains proper ids or You can provide them manually as a array like this:

$products_to_delete = array(1,2,3,4); // 1,2,3,4 are examples! Provide your own ids!

 

It should work after few adjustments but I didn't test it. 

Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

@hakery2 - I know your code is not meant to be exhaustive, but when I tried it, the call to the config.inc.php file prevents any of the remaining code to run. Instead it just loads the shop's front page. 

Am I doing something wrong?

I am on 1.6.x and would just like to load the product class as you've done.

I've put that bit of code in a module folder, and am running it domain.com/modules/delprod/delprod.php

Any help appreciated!

Link to comment
Share on other sites

  • 1 year later...

Hello

Same question but I´d like to delete images, combinations etc... as well.

Admin panel takes a long time to delete ONE product.  I can´t think how long time to delete more than a thousand...

Any solution ?

 

Thanks for help

Link to comment
Share on other sites

rule of thumb, do not delete anything, simply disable

unless the process uses native PS product delete class then you will probably/most likely create issues, for example orders placed on product you delete.

be warned, deleting data via mysql can easily destroy your shop, maybe not visibly as first then later you will start to see unexplainable anomalies, then it's to late.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...
9 hours ago, renzogr said:

hanks for your post Patron.

 

My host is very fast...  But I'd like to clean sql files deleting old products and images.

You can open make a simple PHP

$i=1;
for ($i =1; $i<=1000; $i++) {
            $id_product = $i;
            $pd = new Product($id_product);
            $pd->delete();
            unset($pd);
        }

This script will remove all product ID from 1-> 1000, also it will remove all SQL related to this product, images, combination, specify price...

Link to comment
Share on other sites

On 2/28/2020 at 12:15 AM, renzogr said:

Thank you TDSOFT.

How would this PHP look to delete inactive products instead of IDs?

Great job.

 

Thanks again

 

$i=1;
for ($i =1; $i<=1000; $i++) {
            $id_product = $i;
            $pd = new Product($id_product);
            if ($pd->active == 0) {
            	$pd->delete();
 			}
            unset($pd);
        }

 

Link to comment
Share on other sites

  • 3 months later...

Is there any way to speed up deleting? We are having eshop with 300 000 products and deleting one of them takes around 3 minutes.

I need to bulk delete around 300 products with specified product reference code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...