因此,我试图将新产品导入到我的网上商店,但是我确实需要从特定ID到最后一个ID删除9000种产品。另外,如果该方法删除与产品相关联的图片,那将非常好。
答案 0 :(得分:0)
下面的代码基于此答案[SOLVED] Delete massive products from database (10420 products)。
我刚刚添加了条件WHERE `id_product` BETWEEN 666 AND 9666
。您应该将上下限放在那儿。该代码每次运行都会删除1000个产品,以避免超时。
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.inc.php');
include(dirname(__FILE__) . '/init.php');
$res = Db::getInstance()->executeS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_product` BETWEEN 666 AND 9666 ORDER BY `id_product` DESC LIMIT 1000 ');
echo "<p>(".date('Y/m/d H:i:s').") Starting to delete products...</p>";
if ($res) {
foreach ($res as $row) {
echo "<p>(".date('Y/m/d H:i:s').") Deleting product with ID <b>".$row['id_product']."</b>...";
$p = new Product($row['id_product']);
if(!$p->delete()) {
echo " <span style='color: red'>Error deleting this product!</span></p>";
} else {
echo " <span style='color: green'>DELETED</span></p>";
}
}
}
?>
<script>
window.location.reload();
</script>