set new outside the loop, add fetch result check

This commit is contained in:
Pierre Payet 2021-05-11 20:30:57 +02:00
parent ff178667a3
commit 4ce81ee535

View File

@ -171,6 +171,7 @@ if (empty($reshook))
dol_print_error($db); dol_print_error($db);
} }
$thirdpartystatic = new Societe($db);
// Loop on each email and send it // Loop on each email and send it
$i = 0; $i = 0;
@ -202,11 +203,12 @@ if (empty($reshook))
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions) // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
$substitutionarray['__ID__'] = $obj->source_id; $substitutionarray['__ID__'] = $obj->source_id;
if ($obj->source_type == "thirdparty") { if ($obj->source_type == "thirdparty") {
$thirdpartystatic = new Societe($db); $result = $thirdpartystatic->fetch($obj->source_id);
$thirdpartystatic->fetch($obj->source_id);
$substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client; if ($result > 0) {
$substitutionarray['__THIRDPARTY_CUSTOMER_CODE_WITHOUT_PREFIX__'] = substr($thirdpartystatic->code_client, 1); $substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
$substitutionarray['__THIRDPARTY_CUSTOMER_CODE_WITHOUT_PREFIX__'] = substr($thirdpartystatic->code_client, 1);
}
} }
$substitutionarray['__EMAIL__'] = $obj->email; $substitutionarray['__EMAIL__'] = $obj->email;
$substitutionarray['__LASTNAME__'] = $obj->lastname; $substitutionarray['__LASTNAME__'] = $obj->lastname;