From 6f7788568676a219e60729650b1408e0aaf9389e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 1 Nov 2019 20:26:39 +0100 Subject: [PATCH] Update api_products.class.php --- htdocs/product/class/api_products.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 5b179d487a9..e7046e07f43 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -445,16 +445,18 @@ class Products extends DolibarrApi //'multiprices_default_vat_code'=>$this->product->multiprices_default_vat_code ); } + /** * Get prices per customer for a product * * @param int $id ID of product + * @param string $thirdparty_id Thirdparty id to filter orders of (example '1') {@pattern /^[0-9,]*$/i} * * @return mixed * * @url GET {id}/selling_multiprices/per_customer */ - public function getCustomerPricesPerCustomer($id) + public function getCustomerPricesPerCustomer($id, $thirdparty_id = '') { global $conf; @@ -470,15 +472,18 @@ class Products extends DolibarrApi if (! $result ) { throw new RestException(404, 'Product not found'); } - + if ($result > 0) { require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; $prodcustprice = new Productcustomerprice($this->db); - $result = $prodcustprice->fetch_all('', '', 0, 0, array('t.fk_product' => $id)); + $filter = array(); + $filter['t.fk_product'] .= $id; + if ($thirdparty_id) $filter['t.fk_soc'] .= $thirdparty_id; + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); } if ( empty($prodcustprice->lines)) { - throw new RestException(503, 'Error when retrieve prices list : '.array_merge(array($prodcustprice->error), $prodcustprice->errors)); + throw new RestException(404, 'Prices not found'); } return $prodcustprice->lines;