diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index e962e59264c..ccf255af4d7 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -7517,4 +7517,35 @@ abstract class CommonObject
}
}
}
+
+ /**
+ * copy related categories to another object
+ *
+ * @param int $fromId Id object source
+ * @param int $toId Id object cible
+ * @param string $type Type of category ('product', ...)
+ * @return int < 0 si erreur, > 0 si ok
+ */
+ function cloneCategories($fromId, $toId, $type='')
+ {
+ $this->db->begin();
+
+ if (empty($type)) $type = $this->table_element;
+
+ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+ $categorystatic = new Categorie($this->db);
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_" . $categorystatic->MAP_CAT_TABLE[$type] . " (fk_categorie, fk_product)";
+ $sql.= " SELECT fk_categorie, $toId FROM ".MAIN_DB_PREFIX."categorie_" . $categorystatic->MAP_CAT_TABLE[$type];
+ $sql.= " WHERE fk_product = '".$fromId."'";
+
+ if (! $this->db->query($sql))
+ {
+ $this->db->rollback();die($sql);
+ return -1;
+ }
+
+ $this->db->commit();
+ return 1;
+ }
}
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 401ccc5462e..62c22548f36 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -148,6 +148,7 @@ CloneProduct=Clone product or service
ConfirmCloneProduct=Are you sure you want to clone product or service %s?
CloneContentProduct=Clone all main information of product/service
ClonePricesProduct=Clone prices
+CloneCategoriesProduct=Clone tags/categories linked
CloneCompositionProduct=Clone virtual product/service
CloneCombinationsProduct=Clone product variants
ProductIsUsed=This product is used
diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang
index 77ad53a3eff..be288c604af 100644
--- a/htdocs/langs/fr_FR/products.lang
+++ b/htdocs/langs/fr_FR/products.lang
@@ -147,6 +147,7 @@ CloneProduct=Cloner produit/service
ConfirmCloneProduct=Êtes-vous sûr de vouloir cloner le produit ou service %s ?
CloneContentProduct=Cloner les informations générales du produit/service
ClonePricesProduct=Cloner les prix
+CloneCategoriesProduct=Cloner les catégories associées
CloneCompositionProduct=Cloner le produits packagés
CloneCombinationsProduct=Cloner les variantes
ProductIsUsed=Ce produit est utilisé
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 9becc71bbb8..5354fcde70f 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -522,7 +522,7 @@ if (empty($reshook))
if (GETPOST('clone_categories'))
{
- $result = $object->clone_categories($originalId, $id);
+ $result = $object->cloneCategories($originalId, $id);
if ($result < 1)
{
@@ -1995,7 +1995,7 @@ $formquestionclone=array(
'text' => $langs->trans("ConfirmClone"),
array('type' => 'text', 'name' => 'clone_ref','label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'size'=>24),
array('type' => 'checkbox', 'name' => 'clone_content','label' => $langs->trans("CloneContentProduct"), 'value' => 1),
- array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategories"), 'value' => 1),
+ array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1),
array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true),
);
if (! empty($conf->global->PRODUIT_SOUSPRODUITS))