Update api_products.class.php

This commit is contained in:
ptibogxiv 2019-11-01 20:26:39 +01:00 committed by GitHub
parent bc5e6c867f
commit 6f77885686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;