NEW API Add option $includeifobjectisused to get a product

This commit is contained in:
Laurent Destailleur 2021-03-08 16:17:20 +01:00
parent e3c31aa7b3
commit 66e7a9b283
2 changed files with 26 additions and 17 deletions

View File

@ -1799,8 +1799,7 @@ class Products extends DolibarrApi
} }
/** /**
* Get properties of a product object * Get properties of 1 product object.
*
* Return an array with product information. * Return an array with product information.
* *
* @param int $id ID of product * @param int $id ID of product
@ -1810,13 +1809,14 @@ class Products extends DolibarrApi
* @param int $includestockdata Load also information about stock (slower) * @param int $includestockdata Load also information about stock (slower)
* @param bool $includesubproducts Load information about subproducts (if product is a virtual product) * @param bool $includesubproducts Load information about subproducts (if product is a virtual product)
* @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product)
* @param bool $includeifobjectisused Check if product object is used and set is_object_used with result.
* @return array|mixed Data without useless information * @return array|mixed Data without useless information
* *
* @throws RestException 401 * @throws RestException 401
* @throws RestException 403 * @throws RestException 403
* @throws RestException 404 * @throws RestException 404
*/ */
private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false, $includeparentid = false) private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includeifobjectisused = false)
{ {
if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) { if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode'); throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode');
@ -1871,8 +1871,9 @@ class Products extends DolibarrApi
} }
} }
// product is used if ($includeifobjectisused) {
$this->product->is_object_used = $this->product->isObjectUsed() > 0; $this->product->is_object_used = ($this->product->isObjectUsed() > 0);
}
return $this->_cleanObjectDatas($this->product); return $this->_cleanObjectDatas($this->product);
} }

View File

@ -92,9 +92,9 @@ class Product extends CommonObject
public $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into images.lib.php public $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into images.lib.php
/* /**
* @deprecated * @deprecated
* @see label * @see $label
*/ */
public $libelle; public $libelle;
@ -407,6 +407,14 @@ class Product extends CommonObject
*/ */
public $supplierprices; public $supplierprices;
/**
* Property set to save result of isObjectUsed(). Used for example by Product API.
*
* @var boolean
*/
public $is_object_used;
/** /**
* @var array fields of object product * @var array fields of object product
*/ */