Fix api for deletion of attributes

This commit is contained in:
Laurent Destailleur 2019-11-26 12:58:41 +01:00
parent cb352407eb
commit 30ea48a715
2 changed files with 15 additions and 14 deletions

View File

@ -965,8 +965,8 @@ class Products extends DolibarrApi
/** /**
* Delete attributes by id. * Delete attributes by id.
* *
* @param int $id ID of Attribute * @param int $id ID of Attribute
* @return int * @return int Result of deletion
* *
* @throws RestException * @throws RestException
* @throws 401 * @throws 401
@ -981,12 +981,13 @@ class Products extends DolibarrApi
$prodattr = new ProductAttribute($this->db); $prodattr = new ProductAttribute($this->db);
$prodattr->id = (int) $id; $prodattr->id = (int) $id;
$result = $prodattr->delete(); $result = $prodattr->delete(DolibarrApiAccess::$user);
if ($result > 0) { if ($result <= 0) {
return 1; throw new RestException(500, "Error deleting attribute");
} }
throw new RestException(500, "Error deleting attribute");
return $result;
} }
/** /**
@ -1485,8 +1486,8 @@ class Products extends DolibarrApi
/** /**
* Delete product variants. * Delete product variants.
* *
* @param int $id ID of Variant * @param int $id ID of Variant
* @return int * @return int Result of deletion
* *
* @throws RestException * @throws RestException
* @throws 401 * @throws 401
@ -1502,12 +1503,11 @@ class Products extends DolibarrApi
$prodcomb = new ProductCombination($this->db); $prodcomb = new ProductCombination($this->db);
$prodcomb->id = (int) $id; $prodcomb->id = (int) $id;
$result = $prodcomb->delete(DolibarrApiAccess::$user); $result = $prodcomb->delete(DolibarrApiAccess::$user);
return $result; if ($result <= 0)
if ($result > 0)
{ {
return 1; throw new RestException(500, "Error deleting variant");
} }
throw new RestException(500, "Error deleting variant"); return $result;
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore

View File

@ -174,9 +174,10 @@ class ProductAttribute
/** /**
* Deletes a product attribute * Deletes a product attribute
* *
* @return int <0 KO, >0 OK * @param User $user Object user
* @return int <0 KO, >0 OK
*/ */
public function delete() public function delete($user = null)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $this->id;