This commit is contained in:
Laurent Destailleur 2020-09-04 12:54:23 +02:00 committed by GitHub
parent 8026ee15df
commit 606217fefc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@ -1005,7 +1005,7 @@ class Products extends DolibarrApi
throw new RestException(401);
}
$sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
$sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@ -1021,14 +1021,16 @@ class Products extends DolibarrApi
$attr['ref_ext'] = $result->ref_ext;
$attr['label'] = $result->label;
$attr['rang'] = $result->rang;
$attr['entity'] = $result->entity;
$sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".(int) $result->rowid." AND pac.entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
$result = $this->db->fetch_object($query);
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$attr["is_used_by_products"] = (bool) $result->count;
$attr["is_used_by_products"] = (int) $obj->nb;
return $attr;
}