copy linked categories when cloning a product

This commit is contained in:
Christophe Battarel 2019-03-11 10:00:44 +01:00
parent 749bbcba18
commit 3215e066e4
4 changed files with 42 additions and 0 deletions

View File

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

View File

@ -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 <b>%s</b> ?
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

View File

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

View File

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