Merge pull request #17403 from kastoras/product_variants_api_add_stock_to_response

New/NEW Product Variants API, add variant stock to response
This commit is contained in:
Laurent Destailleur 2021-05-03 19:39:50 +02:00 committed by GitHub
commit 08806a6d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1568,7 +1568,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
@ -1576,7 +1577,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,6 +1590,13 @@ class Products extends DolibarrApi
$prodc2vp = new ProductCombination2ValuePair($this->db);
$combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id);
$combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
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;