Update api_products.class.php

This commit is contained in:
Laurent Destailleur 2020-09-04 13:05:30 +02:00 committed by GitHub
parent 962bb0c698
commit a98c5b9841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1327,20 +1327,16 @@ class Products extends DolibarrApi
$objectval = new ProductAttributeValue($this->db); $objectval = new ProductAttributeValue($this->db);
$return = []; $return = $objectval->fetchAllByProductAttribute((int) $id);
foreach ($objectval->fetchAllByProductAttribute((int) $id) as $result) {
$tmp = new stdClass();
$tmp->fk_product_attribute = (int) $result->fk_product_attribute;
$tmp->id = (int) $result->id;
$tmp->ref = $result->ref;
$tmp->value = $result->value;
$return[] = $tmp;
}
if (count($return) == 0) { if (count($return) == 0) {
throw new RestException(404, 'Attribute values not found'); throw new RestException(404, 'Attribute values not found');
} }
foreach ($return as $key => $val) {
$return[$key] = $this->_cleanObjectDatas($return[$key]);
}
return $return; return $return;
} }
@ -1363,8 +1359,8 @@ class Products extends DolibarrApi
$return = array(); $return = array();
$sql = 'SELECT '; $sql = 'SELECT ';
$sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v '; $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v';
$sql .= "WHERE v.fk_product_attribute = ( SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".strtoupper(trim($ref))."' LIMIT 1)"; $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); $query = $this->db->query($sql);
@ -1375,7 +1371,7 @@ class Products extends DolibarrApi
$tmp->ref = $result->ref; $tmp->ref = $result->ref;
$tmp->value = $result->value; $tmp->value = $result->value;
$return[] = $tmp; $return[] = $this->_cleanObjectDatas($tmp);
} }
return $return; return $return;