diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index f62c00ee81b..d89c2770f64 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -545,8 +545,9 @@ class Orders extends DolibarrApi * * @param int $id Id of order to update * @param int $rowid Row key of the contact in the array contact_ids. + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid} + * @url DELETE {id}/contact/{rowid}/{type} * * @return int * @@ -554,7 +555,7 @@ class Orders extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid) + public function deleteContact($id, $rowid, $type) { if (!DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); @@ -569,10 +570,16 @@ class Orders extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->commande->delete_linked_contact($rowid); + $contacts = $this->commande->liste_contact(); - if (!$result) { - throw new RestException(500, 'Error when deleted the contact'); + foreach ($contacts as $contact) { + if ($contact['id'] == $rowid && $contact['code'] == $type) { + $result = $this->commande->delete_contact($contact['rowid']); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + } } return array(