From 24dec80c7eb0449793b0e9c81023c12bdd5dfca3 Mon Sep 17 00:00:00 2001 From: kastoras Date: Thu, 29 Apr 2021 00:06:47 +0300 Subject: [PATCH] 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;