diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index a2901c1d5e1..c18fb58a49b 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -80,6 +80,9 @@ function product_prepare_head($object) { $head[$h][0] = DOL_URL_ROOT."/product/composition/card.php?id=".$object->id; $head[$h][1] = $langs->trans('AssociatedProducts'); + + $nbFatherAndChild = $object->hasFatherOrChild(); + if ($nbFatherAndChild > 0) $head[$h][1].= ' '.$nbFatherAndChild.''; $head[$h][2] = 'subproduct'; $h++; } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 26e565fd1bc..ff4ea131c85 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3314,6 +3314,32 @@ class Product extends CommonObject } + /** + * Return all parent products for current product (first level only) + * + * @return int Nb of father + child + */ + function hasFatherOrChild() + { + $nb = 0; + + $sql = "SELECT COUNT(pa.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa"; + $sql.= " WHERE pa.fk_product_fils = ".$this->id." OR pa.fk_product_pere = ".$this->id; + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj) $nb = $obj->nb; + } + else + { + return -1; + } + + return $nb; + } + /** * Return all parent products for current product (first level only) *