Merge pull request #10795 from altatof/clonecat

NEW : copy linked categories on product clone process
This commit is contained in:
Laurent Destailleur 2019-09-15 16:34:42 +02:00 committed by GitHub
commit 0194f48041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -153,6 +153,7 @@ RowMaterial=Raw Material
ConfirmCloneProduct=Are you sure you want to clone product or service <b>%s</b>?
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

View File

@ -153,6 +153,8 @@ RowMaterial=Matière première
ConfirmCloneProduct=Êtes-vous sûr de vouloir cloner le produit ou service <b>%s</b> ?
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é

View File

@ -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))