diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 15133af88d7..817713f221b 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -7811,4 +7811,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
+ */
+ public 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 e0a1a5f8fcf..9919767db0f 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -153,6 +153,7 @@ RowMaterial=Raw Material
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 a0473ad8c76..0248f6470a9 100644
--- a/htdocs/langs/fr_FR/products.lang
+++ b/htdocs/langs/fr_FR/products.lang
@@ -153,6 +153,8 @@ RowMaterial=Matière première
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
CloneCompositionProduct=Cloner les produits virtuels
CloneCombinationsProduct=Cloner les variantes
ProductIsUsed=Ce produit est utilisé
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 5be4dc43358..d6dd9e876cd 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -522,6 +522,19 @@ if (empty($reshook))
}
}
+ if (GETPOST('clone_categories'))
+ {
+ $result = $object->cloneCategories($originalId, $id);
+
+ if ($result < 1)
+ {
+ $db->rollback();
+ setEventMessage($langs->trans('ErrorProductClone'), null, 'errors');
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId);
+ exit;
+ }
+ }
+
// $object->clone_fournisseurs($originalId, $id);
$db->commit();
@@ -1951,6 +1964,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("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))