Fix: Fetching category on label is not enough. We must introduce type

This commit is contained in:
Laurent Destailleur 2016-05-25 15:36:48 +02:00
parent b476153b8b
commit b410aa57b9
2 changed files with 7 additions and 6 deletions

View File

@ -167,9 +167,10 @@ class Categorie extends CommonObject
* *
* @param int $id Id of category * @param int $id Id of category
* @param string $label Label of category * @param string $label Label of category
* @param string $type Type of category
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id,$label='') function fetch($id,$label='',$type='')
{ {
global $conf; global $conf;
@ -182,10 +183,10 @@ class Categorie extends CommonObject
{ {
$sql.= " WHERE rowid = '".$id."'"; $sql.= " WHERE rowid = '".$id."'";
} }
else 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); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@ -255,9 +256,9 @@ class Categorie extends CommonObject
if ($this->already_exists()) if ($this->already_exists())
{ {
$this->error=$langs->trans("ImpossibleAddCat"); $this->error=$langs->trans("ImpossibleAddCat", $this->label);
$this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel"); $this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel");
dol_syslog($this->error, LOG_ERR); dol_syslog($this->error, LOG_WARNING);
return -4; return -4;
} }

View File

@ -39,7 +39,7 @@ ErrForgotCat=You forgot to choose the tag/category
ErrForgotField=You forgot to inform the fields ErrForgotField=You forgot to inform the fields
ErrCatAlreadyExists=This name is already used ErrCatAlreadyExists=This name is already used
AddProductToCat=Add this product to a tag/category? 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 ImpossibleAssociateCategory=Impossible to associate the tag/category to
WasAddedSuccessfully=<b>%s</b> was added successfully. WasAddedSuccessfully=<b>%s</b> was added successfully.
ObjectAlreadyLinkedToCategory=Element is already linked to this tag/category. ObjectAlreadyLinkedToCategory=Element is already linked to this tag/category.