diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2f2d24f7458..f66ba06ac27 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -165,9 +165,10 @@ class Products extends DolibarrApi * @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service) * @param int $category Use this param to filter list by category * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)" + * @param bool $ids_only Return only IDs of product instead of all properties (faster, above all if list is long) * @return array Array of product objects */ - public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '') + public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '', $ids_only = false) { global $db, $conf; @@ -219,9 +220,13 @@ class Products extends DolibarrApi $i = 0; while ($i < $min) { $obj = $this->db->fetch_object($result); - $product_static = new Product($this->db); - if ($product_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($product_static); + if (!$ids_only) { + $product_static = new Product($this->db); + if ($product_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($product_static); + } + } else { + $obj_ret[] = $obj->rowid; } $i++; } @@ -1866,6 +1871,9 @@ class Products extends DolibarrApi } } + // product is used + $this->product->is_object_used = $this->product->isObjectUsed() > 0; + return $this->_cleanObjectDatas($this->product); } }