From 8ba08552ca23ff232cbeeeaebf3cb688147a656c Mon Sep 17 00:00:00 2001 From: kastoras Date: Tue, 27 Apr 2021 01:01:27 +0300 Subject: [PATCH 1/6] New/NEW Product Variants API, add variant stock to response When acessing product variants via GET API /products/{id}/variants, Include stock_warehouse data to the response --- htdocs/product/class/api_products.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 9b06b30765d..78afe88c310 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -25,6 +25,7 @@ require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; /** * API class for products @@ -1574,6 +1575,11 @@ class Products extends DolibarrApi $prodc2vp = new ProductCombination2ValuePair($this->db); $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); + + $productModel = new Product($this->db); + $productModel->fetch((int)$combination->fk_product_child); + $productModel->load_stock(); + $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; } return $combinations; From 1c1e111b0c57608ee07c7f9ae352ddc53e82cdcb Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 26 Apr 2021 22:06:11 +0000 Subject: [PATCH 2/6] Fixing style errors. --- 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 78afe88c310..4d06cbce5bc 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1577,7 +1577,7 @@ class Products extends DolibarrApi $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); $productModel = new Product($this->db); - $productModel->fetch((int)$combination->fk_product_child); + $productModel->fetch((int) $combination->fk_product_child); $productModel->load_stock(); $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; } From e5cd6f97f93818fa5f6a62c6f9ab2bdc44459a85 Mon Sep 17 00:00:00 2001 From: kastoras Date: Tue, 27 Apr 2021 01:01:27 +0300 Subject: [PATCH 3/6] New/NEW Product Variants API, add variant stock to response When acessing product variants via GET API /products/{id}/variants, Include stock_warehouse data to the response --- htdocs/product/class/api_products.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 0c70af86c9c..95ad085ddc0 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -25,6 +25,7 @@ require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; /** * API class for products @@ -1587,6 +1588,11 @@ class Products extends DolibarrApi $prodc2vp = new ProductCombination2ValuePair($this->db); $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); + + $productModel = new Product($this->db); + $productModel->fetch((int)$combination->fk_product_child); + $productModel->load_stock(); + $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; } return $combinations; From 24dec80c7eb0449793b0e9c81023c12bdd5dfca3 Mon Sep 17 00:00:00 2001 From: kastoras Date: Thu, 29 Apr 2021 00:06:47 +0300 Subject: [PATCH 4/6] New/NEW Product Variants API, add variant stock to response by parameter If $includestock parameter is set to 1, the response will contain variant stock data --- htdocs/product/class/api_products.class.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 95ad085ddc0..83b19fb35c0 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1567,7 +1567,8 @@ class Products extends DolibarrApi /** * Get product variants. * - * @param int $id ID of Product + * @param int $id ID of Product + * @param int $includestock Default value 0. If parameter is set to 1 the response will contain stock data of each variant * @return array * * @throws RestException 500 @@ -1575,7 +1576,7 @@ class Products extends DolibarrApi * * @url GET {id}/variants */ - public function getVariants($id) + public function getVariants($id,$includestock=0) { if (!DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); @@ -1589,10 +1590,12 @@ class Products extends DolibarrApi $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); - $productModel = new Product($this->db); - $productModel->fetch((int)$combination->fk_product_child); - $productModel->load_stock(); - $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; + if($includestock==1){ + $productModel = new Product($this->db); + $productModel->fetch((int)$combination->fk_product_child); + $productModel->load_stock(); + $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; + } } return $combinations; From 58b4074e57c91fbf75590243b86cad864c651fcd Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 28 Apr 2021 21:10:06 +0000 Subject: [PATCH 5/6] Fixing style errors. --- htdocs/product/class/api_products.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index d94fc1f42d3..62137730e5f 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1568,7 +1568,7 @@ class Products extends DolibarrApi * Get product variants. * * @param int $id ID of Product - * @param int $includestock Default value 0. If parameter is set to 1 the response will contain stock data of each variant + * @param int $includestock Default value 0. If parameter is set to 1 the response will contain stock data of each variant * @return array * * @throws RestException 500 @@ -1576,7 +1576,7 @@ class Products extends DolibarrApi * * @url GET {id}/variants */ - public function getVariants($id,$includestock=0) + public function getVariants($id, $includestock = 0) { if (!DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); @@ -1590,9 +1590,9 @@ class Products extends DolibarrApi $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); - if($includestock==1){ + if ($includestock==1) { $productModel = new Product($this->db); - $productModel->fetch((int)$combination->fk_product_child); + $productModel->fetch((int) $combination->fk_product_child); $productModel->load_stock(); $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; } From 127654e792dc77d23333f7d7faf1641bb4cb22ad Mon Sep 17 00:00:00 2001 From: kastoras Date: Sat, 1 May 2021 22:32:08 +0300 Subject: [PATCH 6/6] New/NEW Product Variants API, add variant stock to response Remove dependency inserded by mistake --- htdocs/product/class/api_products.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 62137730e5f..39d8b8aa83a 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -25,7 +25,6 @@ require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; /** * API class for products