ExecuteS(' SELECT mr_s.* FROM `'._DB_PREFIX_.'mr_selected` mr_s WHERE mr_s.`id_order` IN ( SELECT DISTINCT o.id_order FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON o.`id_order` = d.`id_order` LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON d.`product_id` = c.`id_product` WHERE c.`id_sale` = '.$sale.' AND o.id_carrier = 91 ) AND MR_Selected_Num = "" '); $orderNb = count($order); echo date('Y-m-d H:i:s')." - $orderNb commandes sans num MR\n"; if ($orderNb > 0) { foreach ($order as $o) { // Looks for MR $mr = Db::getInstance()->ExecuteS(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` WHERE colnom = "'.$o['MR_Selected_LgAdr1'].'" AND colrue = "'.$o['MR_Selected_LgAdr3'].'" AND codpos = "'.$o['MR_Selected_CP'].'" '); if (count($mr) == 1) { $relai = $mr[0]; echo "Order ".$o['id_order']." - MR : ".$relai['direction']."\n"; // Update if (!empty($relai['direction'])) { $sql = 'UPDATE `'._DB_PREFIX_.'mr_selected` SET MR_Selected_Num = '.$relai['direction']. ' WHERE id_mr_selected = '.$o['id_mr_selected'].' AND id_order = '.$o['id_order']; if ($optVerbose) { echo $sql."\n"; } if (!$optTest) { Db::getInstance()->ExecuteS($sql); } } } elseif (count($mr) > 1) { echo "Order ".$o['id_order']." - MR > 1 - manual.\n"; } else { echo "Order ".$o['id_order']." - MR not found.\n"; } } } echo date('Y-m-d H:i:s')." - END \n";