/ Published in: PHP
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php "; require_once MAGENTO . '/app/Mage.php'; Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $products = Mage::getModel('catalog/product') ->getCollection() ->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'); $mysqli->query($sql); $count = 0; foreach($products as $product){ $product->delete(); if($count++%100 == 0) { "; } } "; $mysqli->query($undoSql); ?>
URL: http://www.sonassi.com/knowledge-base/magento-knowledge-base/mass-delete-products-in-magento/