Add a drop-down for customer reference in orders

When we create sales orders, we add customer name as reference for 99% of the time. Instead of typing the names all the time it would be neat to just use a select-box as all customer names are added in “Contacts” for the third-party.

So I tried a quick-n-dirty hack in htdocs/commande/card.php:

(near line 1590)
// Reference client                                                                                                                                                                                                                                                
print '<tr><td>'.$langs->trans('RefCustomer').'</td><td>';
$ref_test_foo = "Select reference:" . $form->selectcontacts($soc->id, $contactid, 'ref_client', 1, $srccontactslist, '', 0);
if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
    print '<input type="text" name="ref_client" value="'.$ref_client.'">' . $ref_test_foo . '</td>';
} else {
    print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'">' . $ref_test_foo . '</td>';
}
print '</tr>';

This adds a select-box as we want, and it will store the selection in “ref_client” (which is the same field as where you type the name manually):

However, after creating the order, it seems that the id-number of the contact is added to the reference-field (which kind of makes sense):

This means my quick-hack sort-of works to 50%, but we want the contact name instead of the contact id instead.

Question: Is it possible to make $form->selectcontacts() return the name instead of the id, or will I have to modify that whole function (which I really do not want)?

Because the name of a contact is not unique, $form->selectcontacts() will always return an id, only the id is unique.
For your case this is not a problem, you store the text into a free text property. So you have to create you own selectcontacts2 method.

1 Like

Thanks.

I was afraid I would have to do this. It will break when we upgrade so I will use it for now and make a feature request for it.