silvioscavone Posted February 10, 2018 Share Posted February 10, 2018 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 More sharing options...
musicmaster Posted February 11, 2018 Share Posted February 11, 2018 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 More sharing options...
silvioscavone Posted February 11, 2018 Author Share Posted February 11, 2018 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 More sharing options...
musicmaster Posted February 11, 2018 Share Posted February 11, 2018 (edited) 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 February 11, 2018 by musicmaster (see edit history) Link to comment Share on other sites More sharing options...
silvioscavone Posted February 12, 2018 Author Share Posted February 12, 2018 Hi, I uploaded the script on website root, but it stuck on “Starting to delete products...” Looks like no product on that range has been deleted (I checked the first and the last). I can’t understand the reason. Do you have any explanation? Link to comment Share on other sites More sharing options...
hakeryk2 Posted February 12, 2018 Share Posted February 12, 2018 (edited) 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 June 2, 2020 by hakeryk2 (see edit history) Link to comment Share on other sites More sharing options...
presta911 Posted February 15, 2018 Share Posted February 15, 2018 @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 More sharing options...
hakeryk2 Posted February 15, 2018 Share Posted February 15, 2018 Well, You should turn on debuging mode to true and see what error it is causing and paste it here or get it done by yourself Maybe it is pointing to wrong file, I don't know.https://www.prestashop.com/forums/topic/285199-how-to-enable-debugging-mode-in-prestasho-156/ Link to comment Share on other sites More sharing options...
presta911 Posted February 15, 2018 Share Posted February 15, 2018 Thanks hakeryk2 It was because in the url I needed to reference the shop ID, so: domain.com/modules/delprod/delprod.php?id_shop=1 otherwise it runs something in the config. Link to comment Share on other sites More sharing options...
hakeryk2 Posted February 16, 2018 Share Posted February 16, 2018 I didn't know that You have multistore It was created for non-multistore but I am glad that it works for You. Link to comment Share on other sites More sharing options...
renzogr Posted July 19, 2019 Share Posted July 19, 2019 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 More sharing options...
PrestaHeroes USA Posted July 19, 2019 Share Posted July 19, 2019 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. 1 Link to comment Share on other sites More sharing options...
renzogr Posted July 20, 2019 Share Posted July 20, 2019 Yes, I know. They are already disabled but I'd like to reduce sql tables to improve general perfomance. Thanks anyway Link to comment Share on other sites More sharing options...
PrestaHeroes USA Posted February 26, 2020 Share Posted February 26, 2020 to improve mysql, get faster hosting and if possible nvme ssd...it go zoom freaking zoom lol Link to comment Share on other sites More sharing options...
renzogr Posted February 26, 2020 Share Posted February 26, 2020 hanks for your post Patron. My host is very fast... But I'd like to clean sql files deleting old products and images. Link to comment Share on other sites More sharing options...
tdsoft Posted February 27, 2020 Share Posted February 27, 2020 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 More sharing options...
renzogr Posted February 27, 2020 Share Posted February 27, 2020 Thank you TDSOFT. How would this PHP look to delete inactive products instead of IDs? Great job. Thanks again Link to comment Share on other sites More sharing options...
Guest Posted February 28, 2020 Share Posted February 28, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
renzogr Posted February 28, 2020 Share Posted February 28, 2020 Thanks Guest. I'll test it. Regards Link to comment Share on other sites More sharing options...
Guest Posted February 28, 2020 Share Posted February 28, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
renzogr Posted February 28, 2020 Share Posted February 28, 2020 Thanks again, but I'd like to remove all info related to them. Thanks Link to comment Share on other sites More sharing options...
tdsoft Posted February 29, 2020 Share Posted February 29, 2020 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 More sharing options...
Guest Posted February 29, 2020 Share Posted February 29, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
renzogr Posted February 29, 2020 Share Posted February 29, 2020 Hi Guest I meaning that all data related to that (inactive) product should be deleted: combinations, prices, images... everything. Link to comment Share on other sites More sharing options...
Guest Posted February 29, 2020 Share Posted February 29, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
sooly Posted June 4, 2020 Share Posted June 4, 2020 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 More sharing options...
Guest Posted June 4, 2020 Share Posted June 4, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now