From 10671e3266627c49aeeeaeb4eddb496e3c129284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 5 Oct 2019 21:15:13 +0200 Subject: [PATCH 1/2] api supplier price delete --- htdocs/product/class/api_products.class.php | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 866eeb116cf85..da7cd9fa78099 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -15,10 +15,11 @@ * along with this program. If not, see . */ - use Luracast\Restler\RestException; +use Luracast\Restler\RestException; - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for products @@ -41,6 +42,11 @@ class Products extends DolibarrApi */ public $product; + /** + * @var ProductFournisseur $productsupplier {@type ProductFournisseur} + */ + public $productsupplier; + /** * Constructor */ @@ -49,6 +55,7 @@ public function __construct() global $db, $conf; $this->db = $db; $this->product = new Product($this->db); + $this->productsupplier = new ProductFournisseur($this->db); } /** @@ -475,7 +482,7 @@ public function getCustomerPricesPerQuantity($id) * * @url DELETE {id}/purchase_prices/{priceid} * - * @return array + * @return int * * @throws 401 * @throws 404 @@ -494,13 +501,13 @@ public function deletePurchasePrice($id, $priceid) if(! DolibarrApi::_checkAccessToResource('product', $this->product->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - - if($result) { - $this->product = new ProductFournisseur($this->db); - $this->product->fetch($id); + $resultsupplier = 0; + if ($result) { + $this->productsupplier->fetch($id); + $resultsupplier = $this->product->remove_product_fournisseur_price($priceid); } - return $this->product->remove_product_fournisseur_price($priceid); + return $resultsupplier; } /** @@ -632,13 +639,13 @@ public function getPurchasePrices($id, $ref = '', $ref_ext = '', $barcode = '', } if ($includestockdata) { - $this->product->load_stock(); + $this->product->load_stock(); } if($result) { - $this->product = new ProductFournisseur($this->db); - $this->product->fetch($id, $ref); - $this->product->list_product_fournisseur_price($id, '', '', 0, 0); + $this->product = new ProductFournisseur($this->db); + $this->product->fetch($id, $ref); + $this->product->list_product_fournisseur_price($id, '', '', 0, 0); } return $this->_cleanObjectDatas($this->product); From b895f8a78f4d03b5c6acbc0c785d79e260dc166b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 5 Oct 2019 21:19:55 +0200 Subject: [PATCH 2/2] api supplier get purchase prices --- htdocs/product/class/api_products.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index da7cd9fa78099..346aef06a91b6 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -642,13 +642,12 @@ public function getPurchasePrices($id, $ref = '', $ref_ext = '', $barcode = '', $this->product->load_stock(); } - if($result) { - $this->product = new ProductFournisseur($this->db); - $this->product->fetch($id, $ref); - $this->product->list_product_fournisseur_price($id, '', '', 0, 0); + if ($result) { + $this->productsupplier->fetch($id, $ref); + $this->productsupplier->list_product_fournisseur_price($id, '', '', 0, 0); } - return $this->_cleanObjectDatas($this->product); + return $this->_cleanObjectDatas($this->productsupplier); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore