ExecuteS(' SELECT pc.`id_category` FROM `'._DB_PREFIX_.'privatesale_category` pc LEFT JOIN `'._DB_PREFIX_.'privatesale` p ON (p.id_sale = pc.id_sale) WHERE p.`braderie` = 1 ') as $c){ $categories[] = $c['id_category']; } foreach ($categories as $key => $id_category) { $products = Db::getInstance()->ExecuteS(' SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_product` cp RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1) WHERE cp.id_category ='.(int)$id_category.' AND p.quantity != 0 ORDER BY cp.`position` '); if($products){ foreach ($products as $key => $product) { Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'category_product` SET `position` = '. (int)($key) .' WHERE `id_product` = '.(int)($product['id_product']).' AND `id_category`='.(int)$id_category ); } } $products_zero = Db::getInstance()->ExecuteS(' SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_product` cp RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1) WHERE cp.id_category ='.(int)$id_category.' AND p.quantity = 0 ORDER BY cp.`position` '); if($products_zero){ $position = count($products); foreach ($products_zero as $key => $product) { Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'category_product` SET `position` = '. (int)($position) .' WHERE `id_product` = '.(int)($product['id_product']).' AND `id_category`='.(int)$id_category ); $position++; } } }