diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php
index d6cb6df2bb2..51b0b76ee23 100644
--- a/htdocs/categories/categorie.class.php
+++ b/htdocs/categories/categorie.class.php
@@ -670,6 +670,35 @@ class Categorie
}
}
+ /**
+ * Retourne les catégories contenant le produit $ref
+ */
+ function containing_ref ($ref)
+ {
+ $cats = array ();
+
+ $sql = "SELECT c.fk_categorie, c.fk_product, p.rowid, p.label";
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie_product as c, ".MAIN_DB_PREFIX."product as p";
+ $sql.= " WHERE p.label = '".$ref."' AND c.fk_product = p.rowid";
+
+ $res = $this->db->query ($sql);
+
+ if ($res)
+ {
+ while ($cat = $this->db->fetch_array ($res))
+ {
+ $cats[] = new Categorie ($this->db, $cat['fk_categorie']);
+ }
+
+ return $cats;
+ }
+ else
+ {
+ dolibarr_print_error ($this->db);
+ return -1;
+ }
+ }
+
/**
* Retourne les catégories dont le nom correspond ŕ $nom
* ajoute des wildcards sauf si $exact = true
diff --git a/htdocs/product/categorie.php b/htdocs/product/categorie.php
index 9b3e996f59c..55abdec5146 100644
--- a/htdocs/product/categorie.php
+++ b/htdocs/product/categorie.php
@@ -149,8 +149,16 @@ if ($_GET["id"] || $_GET["ref"])
print '';
$c = new Categorie($db);
- $cats = $c->containing($_REQUEST['id']);
+ if ($_GET["id"])
+ {
+ $cats = $c->containing($_REQUEST['id']);
+ }
+ else
+ {
+ $cats = $c->containing_ref($_REQUEST['ref']);
+ }
+
if (sizeof($cats) > 0)
{
print "Vous avez stocké le produit dans les catégorie suivantes:
";