From d6abd9305f8e1e1d7efeffec09d58bf9a00ae81e Mon Sep 17 00:00:00 2001 From: spsolauv Date: Mon, 5 Jan 2026 23:45:26 +0100 Subject: [PATCH] Make CommonObject::cloneCategories() generic (#36758) It was working only for products Co-authored-by: Laurent Destailleur --- htdocs/core/class/commonobject.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d3b056dac9d..d90974d72d3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -11529,9 +11529,12 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $categorystatic = new Categorie($this->db); - $sql = "INSERT INTO ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; - $sql .= " SELECT fk_categorie, $toId FROM ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); - $sql .= " WHERE fk_product = ".((int) $fromId); + $tablename = $this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); + $fkname = 'fk_' . (empty($categorystatic->MAP_CAT_FK[$type]) ? $type : $categorystatic->MAP_CAT_FK[$type]); + + $sql = "INSERT INTO ".$tablename." (fk_categorie, ".$fkname.")"; + $sql .= " SELECT fk_categorie, $toId FROM ".$tablename; + $sql .= " WHERE ".$fkname." = ".((int) $fromId); if (!$this->db->query($sql)) { $this->error = $this->db->lasterror();