Anyone who has used Magento knows that deleting muliple products can be a slow & tiresome process – the “Delete All” function will often result in Server 500 errors if you have more than 100 products.
Up until now I have just bitten the bullet, put some good background music on and deleted the products a page at a time (inwardly cursing that Magento promises so much and delivers little)
But having to do lots of product imports I thought I’d investigate a better way of deleting.
I found this splendid blog post by Sonassi here:
http://www.sonassi.com/knowledge-base/magento-knowledge-base/mass-delete-products-in-magento
Which goes some way to showing how its done.
1) Basically I took their code and put it into a php file called “mass-delete.php“
2) I put this file in a subfolder in my magento site (“my-functions“) – for neatness
3) I edited my .htaccess so i coudl run functions from thsi folder – find teh other similar looking lines and add:
RewriteCond %{REQUEST_URI} !^/my-functions/
The php file also needs editing if you want it to run on ALL products. Just remove the line that says:
->addFieldToFilter('data_set', 1544);
Then you’re ready to run this in your browser:
http://www.yoursite.com/myfunctions/mass-delete.php
Warnings:
1) This script does take a long time to run. Mine has caused Server 500 errors – but I’ve found its best just to re-refresh the page and it starts off where it left off
2) Whatever you do make sure you let teh script finish what its doing. Becasue at teh end of the script it switches the inedex types back to Update on Save (as it turns it to Manual at the start) which wil mean your site behaves normally once again. (I didn’t and couldn’t see any of my products. Took me a while to realise I have to change the update types on my indexes manually)
I hope this helps anyone getting that Sonassi script to work for them