From b410aa57b98bd3732d725dd4a0ddb47cf85f48bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 25 May 2016 15:36:48 +0200 Subject: [PATCH] Fix: Fetching category on label is not enough. We must introduce type --- htdocs/categories/class/categorie.class.php | 11 ++++++----- htdocs/langs/en_US/categories.lang | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 672ea7b6408..e4c6f162d23 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -167,9 +167,10 @@ class Categorie extends CommonObject * * @param int $id Id of category * @param string $label Label of category + * @param string $type Type of category * @return int <0 if KO, >0 if OK */ - function fetch($id,$label='') + function fetch($id,$label='',$type='') { global $conf; @@ -182,10 +183,10 @@ class Categorie extends CommonObject { $sql.= " WHERE rowid = '".$id."'"; } - else { - if ($label) $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category',1).")"; + $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category',1).")"; + if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -255,9 +256,9 @@ class Categorie extends CommonObject if ($this->already_exists()) { - $this->error=$langs->trans("ImpossibleAddCat"); + $this->error=$langs->trans("ImpossibleAddCat", $this->label); $this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel"); - dol_syslog($this->error, LOG_ERR); + dol_syslog($this->error, LOG_WARNING); return -4; } diff --git a/htdocs/langs/en_US/categories.lang b/htdocs/langs/en_US/categories.lang index 0235b51ccb3..4a569316425 100644 --- a/htdocs/langs/en_US/categories.lang +++ b/htdocs/langs/en_US/categories.lang @@ -39,7 +39,7 @@ ErrForgotCat=You forgot to choose the tag/category ErrForgotField=You forgot to inform the fields ErrCatAlreadyExists=This name is already used AddProductToCat=Add this product to a tag/category? -ImpossibleAddCat=Impossible to add the tag/category +ImpossibleAddCat=Impossible to add the tag/category %s ImpossibleAssociateCategory=Impossible to associate the tag/category to WasAddedSuccessfully=%s was added successfully. ObjectAlreadyLinkedToCategory=Element is already linked to this tag/category.