diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 401ccc5462e..9c96f12c589 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -147,6 +147,7 @@ RowMaterial=Raw Material
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
+CloneCategoriesProduct=Clone tags/categories linked
ClonePricesProduct=Clone prices
CloneCompositionProduct=Clone virtual product/service
CloneCombinationsProduct=Clone product variants
diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang
index 77ad53a3eff..2339a0c921f 100644
--- a/htdocs/langs/fr_FR/products.lang
+++ b/htdocs/langs/fr_FR/products.lang
@@ -146,6 +146,7 @@ RowMaterial=Matière première
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
+CloneCategoriesProduct=Cloner les catégories associées
ClonePricesProduct=Cloner les prix
CloneCompositionProduct=Cloner le produits packagés
CloneCombinationsProduct=Cloner les variantes
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 18ea87cb03a..e433b9a6558 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -520,6 +520,19 @@ if (empty($reshook))
}
}
+ if (GETPOST('clone_categories'))
+ {
+ $result = $object->clone_categories($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();
@@ -1982,6 +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("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))
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 51a5d7c72d0..3466625dfe5 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3611,6 +3611,32 @@ class Product extends CommonObject
return 1;
}
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * copy related categories to another product
+ *
+ * @param int $fromId Id produit source
+ * @param int $toId Id produit cible
+ * @return int < 0 si erreur, > 0 si ok
+ */
+ function clone_categories($fromId, $toId)
+ {
+ $this->db->begin();
+
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'categorie_product (fk_categorie, fk_product)';
+ $sql.= " SELECT fk_categorie, $toId FROM ".MAIN_DB_PREFIX."categorie_product";
+ $sql.= " WHERE fk_product = '".$fromId."'";
+
+ if (! $this->db->query($sql))
+ {
+ $this->db->rollback();
+ return -1;
+ }
+
+ $this->db->commit();
+ return 1;
+ }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre