Fixing style errors.

This commit is contained in:
stickler-ci 2019-11-17 00:18:43 +00:00
parent 8c057f1975
commit a17e183da9

View File

@ -802,7 +802,7 @@ class Products extends DolibarrApi
return $this->_cleanObjectDatas($this->productsupplier);
}
/**
* Get attributes.
*
@ -813,15 +813,15 @@ class Products extends DolibarrApi
* @url GET attributes
*/
public function getAttributes()
{
{
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
return $prodattr->fetchAll();
}
/**
* Get attribute by ID.
*
@ -839,17 +839,17 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$result = $prodattr->fetch((int) $id);
if($result < 0) {
throw new RestException(404, "Attribute not found");
}
return $prodattr;
}
/**
* Add attributes.
*
@ -867,18 +867,18 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$prodattr->label = $label;
$prodattr->ref = $ref;
$resid = $prodattr->create(DolibarrApiAccess::$user);
if ($resid <= 0) {
throw new RestException(500, "Error creating new attribute");
}
return $resid;
}
/**
* Update attributes by id.
*
@ -898,26 +898,26 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$result = $prodattr->fetch((int) $id);
if ($result == 0) {
throw new RestException(404, 'Attribute not found');
} elseif ($result < 0) {
throw new RestException(500, "Error fetching attribute");
}
$prodattr->label = $label;
$prodattr->ref = $ref;
if ($prodattr->update(DolibarrApiAccess::$user) > 0) {
return 1;
}
throw new RestException(500, "Error updating attribute");
}
/**
* Delete attributes by id.
*
@ -934,17 +934,17 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$prodattr->id = (int) $id;
$result = $prodattr->delete();
if ($result > 0) {
return 1;
}
throw new RestException(500, "Error deleting attribute");
}
/**
* Delete attributes by ref.
*
@ -961,15 +961,15 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."'";
if ($this->db->query($sql)) {
return 1;
}
throw new RestException(500, "Error deleting attribute");
}
/**
* Get all values for an attribute id.
*
@ -986,11 +986,11 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$objectval = new ProductAttributeValue($this->db);
return $objectval->fetchAllByProductAttribute((int) $id);
}
/**
* Get all values for an attribute ref.
*
@ -1007,28 +1007,28 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$return = array();
$sql = 'SELECT ';
$sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v ';
$sql .= "WHERE v.fk_product_attribute = ( SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". strtoupper(trim($ref)) ."' LIMIT 1)";
$query = $this->db->query($sql);
while ($result = $this->db->fetch_object($query)) {
$tmp = new ProductAttributeValue($this->db);
$tmp->fk_product_attribute = $result->fk_product_attribute;
$tmp->id = $result->rowid;
$tmp->ref = $result->ref;
$tmp->value = $result->value;
$return[] = $tmp;
}
return $return;
}
/**
* Add attribute value.
*
@ -1047,22 +1047,22 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
if (empty($ref) || empty($value)) {
throw new RestException(401);
}
$objectval = new ProductAttributeValue($this->db);
$objectval->fk_product_attribute = $id;
$objectval->ref = $ref;
$objectval->value = $value;
if ($objectval->create(DolibarrApiAccess::$user) > 0) {
return $objectval->id;
}
throw new RestException(500, "Error creating new attribute value");
}
/**
* Delete attribute value by id.
*
@ -1079,16 +1079,16 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$objectval = new ProductAttributeValue($this->db);
$objectval->id = (int) $id;
if ($objectval->delete() > 0) {
return 1;
}
throw new RestException(500, "Error deleting attribute value");
}
/**
* Delete attribute value by ref.
*
@ -1105,16 +1105,16 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."'";
if ($this->db->query($sql)) {
return 1;
}
throw new RestException(500, "Error deleting attribute value");
}
/**
* Get product variants.
*
@ -1131,11 +1131,11 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$prodcomb = new ProductCombination($this->db);
return $prodcomb->fetchAllByFkProductParent((int) $id);
}
/**
* Get product variants by Product ref.
*
@ -1152,19 +1152,19 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) {
throw new RestException(401);
}
$result = $this->product->fetch('', $ref);
if(! $result ) {
throw new RestException(404, 'Product not found');
}
$prodcomb = new ProductCombination($this->db);
return $prodcomb->fetchAllByFkProductParent((int) $this->product->id);
}
/**
* Add variant.
*
*
* "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...)
*
* @param int $id ID of Product
@ -1185,11 +1185,11 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401);
}
if (empty($id) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$prodattr_val = new ProductAttributeValue($this->db);
foreach ($features as $id_attr => $id_value) {
@ -1200,12 +1200,12 @@ class Products extends DolibarrApi
throw new RestException(401);
}
}
$result = $this->product->fetch((int) $id);
if(! $result ) {
throw new RestException(404, 'Product not found');
}
$prodcomb = new ProductCombination($this->db);
if (! $prodcomb->fetchByProductCombination2ValuePairs($id, $features))
{
@ -1220,10 +1220,10 @@ class Products extends DolibarrApi
return $prodcomb->id;
}
}
/**
* Add variant by product ref.
*
*
* "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...)
*
* @param string $ref Ref of Product
@ -1244,11 +1244,11 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401);
}
if (empty($ref) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) {
throw new RestException(401);
}
$prodattr = new ProductAttribute($this->db);
$prodattr_val = new ProductAttributeValue($this->db);
foreach ($features as $id_attr => $id_value) {
@ -1259,16 +1259,16 @@ class Products extends DolibarrApi
throw new RestException(404);
}
}
$result = $this->product->fetch('', trim($ref));
if(! $result ) {
throw new RestException(404, 'Product not found');
}
$prodcomb = new ProductCombination($this->db);
if (! $prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features))
{
$result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
$result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
if ($result > 0)
{
return $result;
@ -1279,7 +1279,7 @@ class Products extends DolibarrApi
return $prodcomb->id;
}
}
/**
* Put product variants.
*
@ -1297,18 +1297,18 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401);
}
$prodcomb = new ProductCombination($this->db);
$prodcomb->fetch((int) $id);
$old_prodcomb = dol_clone($prodcomb, 0);
foreach($request_data as $field => $value) {
if ($field == 'rowid') { continue;
}
$prodcomb->$field = $value;
}
$result = $prodcomb->update(DolibarrApiAccess::$user);
if ($result > 0)
{
@ -1316,7 +1316,7 @@ class Products extends DolibarrApi
}
throw new RestException(500, "Error editing variant");
}
/**
* Delete product variants.
*
@ -1333,7 +1333,7 @@ class Products extends DolibarrApi
if(! (DolibarrApiAccess::$user->rights->produit->supprimer || DolibarrApiAccess::$user->rights->service->supprimer)) {
throw new RestException(401);
}
$prodcomb = new ProductCombination($this->db);
$prodcomb->id = (int) $id;
$result = $prodcomb->delete(DolibarrApiAccess::$user);