Skip to content

Commit

Permalink
Merge pull request #10795 from altatof/clonecat
Browse files Browse the repository at this point in the history
NEW : copy linked categories on product clone process
  • Loading branch information
eldy committed Sep 15, 2019
2 parents 23860b1 + cd96238 commit 0194f48
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -7811,4 +7811,35 @@ public function trimParameters($parameters)
}
}
}

/**
* 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;
}
}
1 change: 1 addition & 0 deletions htdocs/langs/en_US/products.lang
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/fr_FR/products.lang
Expand Up @@ -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é
Expand Down
14 changes: 14 additions & 0 deletions htdocs/product/card.php
Expand Up @@ -522,6 +522,19 @@
}
}

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();
Expand Down Expand Up @@ -1951,6 +1964,7 @@
'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))
Expand Down

0 comments on commit 0194f48

Please sign in to comment.