if ($sql) { $product_ids = Db::getInstance()->ExecuteS($sql); $beginTime = microtime(true); foreach ($product_ids as $product_id) { /** * PLICIWEB : modification de la requete dans le else if */ if (version_compare(_PS_VERSION_, '1.7.2', '<') AND !Configuration::get('PMS_USE_SYNCHRONIZE')) $q = "UPDATE "._DB_PREFIX_."stock_available sa1 SET `quantity`=( SELECT SUM(quantity) FROM (SELECT * FROM "._DB_PREFIX_."stock_available) sa2 WHERE sa2.id_product=sa1.id_product AND sa2.id_product_attribute >0 GROUP BY sa2.id_product) WHERE sa1.id_product=".$product_id['id_product']." AND sa1.id_product_attribute=0"; else if (version_compare(_PS_VERSION_, '1.7.2', '>=')) { $sqlGetQuantities = " SELECT id_product, SUM(GREATEST(0, quantity)) as q, SUM(physical_quantity) as pq FROM "._DB_PREFIX_."stock_available WHERE id_product = ".(int)$product_id['id_product'] . " AND id_product_attribute > 0 "; $getQuantities = Db::getInstance()->getRow($sqlGetQuantities, false); if (!empty($getQuantities)) { $sqlUpdateQuantities = "UPDATE "._DB_PREFIX_."stock_available SET `physical_quantity` = " . (int) $getQuantities['pq'] . ", `quantity` = " . (int) $getQuantities['q'] . " WHERE id_product = ".(int)$product_id['id_product']." AND id_product_attribute = 0"; } $result = Db::getInstance()->execute($sqlUpdateQuantities, false); $parent_updates++; } } $totalTime = microtime(true) - $beginTime; echo 'Update ' . $parent_updates . ' parents took ' . $totalTime . ' ms' . "\n"; fwrite($handle,"[".date("Y-m-d H:i:s")."] ".$_SERVER['QUERY_STRING'].' Update ' . $parent_updates . ' parents took ' . $totalTime . ' ms' . "\n"); }