From 0f80ba5353be4990929026e5ae945fc542745e01 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 1 Nov 2019 15:36:48 +0100 Subject: [PATCH 1/4] FIX prices by customer API --- htdocs/product/class/api_products.class.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index d6066b1a03a..1b5e8adf862 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -445,7 +445,6 @@ class Products extends DolibarrApi //'multiprices_default_vat_code'=>$this->product->multiprices_default_vat_code ); } - /** * Get prices per customer for a product * @@ -471,13 +470,18 @@ class Products extends DolibarrApi if (! $result ) { throw new RestException(404, 'Product not found'); } - - if ($result < 0) { - throw new RestException(503, 'Error when retrieve prices list : '.array_merge(array($this->product->error), $this->product->errors)); + + 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)); } - throw new RestException(501, 'Feature not yet available'); - //return $result; + if ( empty($prodcustprice->lines)) { + throw new RestException(503, 'Error when retrieve prices list : '.array_merge(array($prodcustprice->error), $prodcustprice->errors)); + } + + return $prodcustprice->lines; } /** From bc5e6c867f4969a5b1697e164e1f033562144661 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 1 Nov 2019 14:37:21 +0000 Subject: [PATCH 2/4] 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 1b5e8adf862..5b179d487a9 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -470,11 +470,11 @@ 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)); + 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)); } if ( empty($prodcustprice->lines)) { From 6f7788568676a219e60729650b1408e0aaf9389e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 1 Nov 2019 20:26:39 +0100 Subject: [PATCH 3/4] 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; From 0e260c859b92d1dc533dcec7874ffb29ff6fbc82 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 1 Nov 2019 19:28:39 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/product/class/api_products.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index e7046e07f43..1b0020faa25 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -445,7 +445,7 @@ class Products extends DolibarrApi //'multiprices_default_vat_code'=>$this->product->multiprices_default_vat_code ); } - + /** * Get prices per customer for a product * @@ -472,13 +472,13 @@ 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); $filter = array(); $filter['t.fk_product'] .= $id; - if ($thirdparty_id) $filter['t.fk_soc'] .= $thirdparty_id; + if ($thirdparty_id) $filter['t.fk_soc'] .= $thirdparty_id; $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); }