From ea1baefe9a5edab606f20588169943860c954e95 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 15 Sep 2019 20:50:18 +0200 Subject: [PATCH] NEW: delete purchase price API --- htdocs/product/class/api_products.class.php | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 756bbde5b29..ad8170921ae 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -467,6 +467,41 @@ class Products extends DolibarrApi ); } + /** + * Delete purchase price for a product + * + * @param int $id Product ID + * @param int $priceid purchase price ID + * + * @url DELETE {id}/purchase_prices/{priceid} + * + * @return array + * + * @throws 401 + * @throws 404 + * + */ + public function deletePurchasePrice($id, $priceid) + { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { + throw new RestException(401); + } + $result = $this->product->fetch($id); + if(! $result ) { + throw new RestException(404, 'Product not found'); + } + + 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); + } + + return $this->product->remove_product_fournisseur_price($priceid); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /**