Hi,
I´d like to delete all not used (= not used in any order) obsolete products from catalogue and therefore I´ve prepared the following script:
<?php
include (dirname(__FILE__).'/config/config.inc.php');
include (dirname(__FILE__).'/init.php');
$defaultLanguageId = intval(Configuration::get('PS_LANG_DEFAULT'));
$home = Configuration::get('PS_HOME_CATEGORY');
$table_product = _DB_PREFIX_.'product';
$table_orders = _DB_PREFIX_.'order_detail';
include_once('config/settings.inc.php');
//připojení k databázi
@$spojenie = MySQL_Connect(_DB_SERVER_ ,_DB_USER_, _DB_PASSWD_);
@MySQL_Select_DB(_DB_NAME_);
if (!$spojenie):
echo "Spatne pristupove udaje do databaze!!!";
endif;
mysql_query("SET NAMES 'utf8'");
$result = mysql_query("SELECT a.id_product FROM $table_product AS a LEFT JOIN $table_orders AS b ON a.id_product = b.product_id WHERE a.active =0 AND b.product_id IS NULL") or die("Chyba ve funkci clear_cat1 : " . mysql_error());
while ( $row = mysql_fetch_assoc($result) ) {
echo "Deleting product ID: ".$row[id_product]."<br>";
$product = new Product((int)$row[id_product]);
$product->delete();
}
mysql_free_result($result);
?>
The problem is that although there are a lot of such products in catalogue, but the script delete only the first found product and than breaks. Is there any internal restriction in Prestashop that multiple deletion of products is restricted? Or am I missing some parameter to set?
PS: If I correct the script only to print the selected product ID´s, it works. Means the break comes after $product->delete(); .