From 1f55f50d19ae636a8dee294c2d5ff3f5e902c26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 6 Mar 2021 19:46:30 +0100 Subject: [PATCH 1/8] NEW API Get the list of product ids only --- htdocs/product/class/api_products.class.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2f2d24f7458..c0a984981a9 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 Get a list of product ids * @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,10 +220,14 @@ 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; + } $i++; } } else { From 7ae57fb8d05f608b496b880dcbca9f514a84e4c6 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 6 Mar 2021 18:48:55 +0000 Subject: [PATCH 2/8] Fixing style errors. --- htdocs/product/class/api_products.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index c0a984981a9..05bf0253519 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -165,7 +165,7 @@ 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 Get a list of product ids + * @param bool $ids_only Get a list of product ids * @return array Array of product objects */ public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '', $ids_only = false) @@ -221,13 +221,13 @@ class Products extends DolibarrApi while ($i < $min) { $obj = $this->db->fetch_object($result); 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; - } + $product_static = new Product($this->db); + if ($product_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($product_static); + } + } else { + $obj_ret[] = $obj; + } $i++; } } else { From 5fc5d9ab488c50a57d12481a594869841ac31bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:12:29 +0100 Subject: [PATCH 3/8] Update api_products.class.php --- htdocs/product/class/api_products.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 05bf0253519..e92950f5e2a 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -226,7 +226,7 @@ class Products extends DolibarrApi $obj_ret[] = $this->_cleanObjectDatas($product_static); } } else { - $obj_ret[] = $obj; + $obj_ret[] = $obj->rowid; } $i++; } From 15fe2a72054984b38a804841cee6f7a94026faf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Mon, 8 Mar 2021 13:25:01 +0100 Subject: [PATCH 4/8] indicate if the product is used --- htdocs/product/class/api_products.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index e92950f5e2a..2e12c1cb503 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1870,6 +1870,9 @@ class Products extends DolibarrApi $this->product->fk_product_parent = $fk_product_parent; } } + + // product is used + $this->product->is_object_used = $this->product->isObjectUsed(); return $this->_cleanObjectDatas($this->product); } From 01db1161b604d5ae3afba24717bfa858b3cdc71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Mon, 8 Mar 2021 13:25:31 +0100 Subject: [PATCH 5/8] Update api_products.class.php --- htdocs/product/class/api_products.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2e12c1cb503..a1c0e3d8cb6 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1872,7 +1872,7 @@ class Products extends DolibarrApi } // product is used - $this->product->is_object_used = $this->product->isObjectUsed(); + $this->product->is_object_used = $this->product->isObjectUsed() > 0; return $this->_cleanObjectDatas($this->product); } From 66230c3f244cd4dd35069dafec34975f9a190577 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 8 Mar 2021 12:27:24 +0000 Subject: [PATCH 6/8] Fixing style errors. --- htdocs/product/class/api_products.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index a1c0e3d8cb6..9bd9b5898e9 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1870,9 +1870,9 @@ class Products extends DolibarrApi $this->product->fk_product_parent = $fk_product_parent; } } - + // product is used - $this->product->is_object_used = $this->product->isObjectUsed() > 0; + $this->product->is_object_used = $this->product->isObjectUsed() > 0; return $this->_cleanObjectDatas($this->product); } From 67211d24fbc6f12134e673e90608c9a8b0af8ba6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Mar 2021 16:07:30 +0100 Subject: [PATCH 7/8] Update api_products.class.php --- htdocs/product/class/api_products.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 9bd9b5898e9..9dc2bf665cd 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -165,7 +165,7 @@ 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 Get a list of product ids + * @param bool $ids_only Return only IDs of product instead of all properties * @return array Array of product objects */ public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '', $ids_only = false) From 6367b843c3c4a97a287ab0b25b479a1694ea1c9f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Mar 2021 16:08:18 +0100 Subject: [PATCH 8/8] Update api_products.class.php --- htdocs/product/class/api_products.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 9dc2bf665cd..f66ba06ac27 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -165,7 +165,7 @@ 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 + * @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 = '', $ids_only = false)