Return to Snippet

Revision: 39054
at January 12, 2011 22:03 by TheJasonParker

Initial Code
echo "Started ".date("d/m/y h:i:s")."
define('MAGENTO', "/domains/");
require_once MAGENTO . '/app/Mage.php';
$products = Mage::getModel('catalog/product')
->addFieldToFilter('data_set', 1544);
$sql = ""; $undoSql = "";
for ($i=0; $i<=8; $i++) {
$sql .= "UPDATE index_process SET mode = 'manual' WHERE index_process.process_id =$i LIMIT 1;";
$undoSql .= "UPDATE index_process SET mode = 'real_time' WHERE index_process.process_id =$i LIMIT 1;";
$mysqli = Mage::getSingleton('core/resource')->getConnection('core_write');
$total_products = count($products);
$count = 0;
foreach($products as $product){
if($count++%100 == 0) {
$cur = strtotime(date("d/m/y h:i:s")) - $time;
$time = strtotime(date("d/m/y h:i:s"));
echo round((($count/$total_products)*100),2)."% deleted ($count/$total_products) ".round(100/$cur)." p/s ".date("h:i:s")."
echo "Ended ".date("d/m/y h:i:s")."

Initial URL

Initial Description
The easiest way to pull this off is by means of a quick script. The key to this script is that the indexing functionality is disabled entirely for the process, then enabled again at the end – requiring a manual update at the end.

In our case, we filtered the type of products by its “Data Set” – an attribute assigned to that batch of products, but you can change this to suit any means of filtering.

Initial Title
Mass delete products for Magento 1.4+

Initial Tags

Initial Language