Can get order by ref, ref_ext, ref_int

This commit is contained in:
c3do 2019-10-19 23:42:55 +02:00
parent ae3ce37a57
commit 4292d72ea3

View File

@ -52,7 +52,7 @@ class Orders extends DolibarrApi
} }
/** /**
* Get properties of an order object * Get properties of an order object by id
* *
* Return an array with order informations * Return an array with order informations
* *
@ -63,12 +63,85 @@ class Orders extends DolibarrApi
* @throws RestException * @throws RestException
*/ */
public function get($id, $contact_list = 1) public function get($id, $contact_list = 1)
{
return $this->_fetch($id, '', '', '', $contact_list);
}
/**
* Get properties of an order object by ref
*
* Return an array with order informations
*
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET byRef/{ref}
*
* @throws RestException
*/
public function getByRef($ref, $contact_list = 1)
{
return $this->_fetch('', $ref, '', '', $contact_list);
}
/**
* Get properties of an order object by ref_ext
*
* Return an array with order informations
*
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET byRefExt/{ref_ext}
*
* @throws RestException
*/
public function getByRefExt($ref_ext, $contact_list = 1)
{
return $this->_fetch('', '', $ref_ext, '', $contact_list);
}
/**
* Get properties of an order object by ref_int
*
* Return an array with order informations
*
* @param string $ref_int Internal reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET byRefInt/{ref_int}
*
* @throws RestException
*/
public function getByRefInt($ref_int, $contact_list = 1)
{
return $this->_fetch('', '', '', $ref_int, $contact_list);
}
/**
* Get properties of an order object
*
* Return an array with order informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other objec
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @throws RestException
*/
private function _fetch($id, $ref = '', $ref_ext = '', $ref_int = '', $contact_list = 1)
{ {
if(! DolibarrApiAccess::$user->rights->commande->lire) { if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id, $ref, $ref_ext, $ref_int);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
@ -83,8 +156,6 @@ class Orders extends DolibarrApi
return $this->_cleanObjectDatas($this->commande); return $this->_cleanObjectDatas($this->commande);
} }
/** /**
* List orders * List orders
* *