Skip to content

Commit

Permalink
copy linked categories when cloning a product
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Battarel committed Mar 11, 2019
1 parent 749bbcb commit 3215e06
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions htdocs/langs/en_US/products.lang
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/products.lang
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions htdocs/product/card.php
Expand Up @@ -520,6 +520,19 @@
}
}

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();
Expand Down Expand Up @@ -1982,6 +1995,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
26 changes: 26 additions & 0 deletions htdocs/product/class/product.class.php
Expand Up @@ -3611,6 +3611,32 @@ public function clone_associations($fromId, $toId)
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
Expand Down

0 comments on commit 3215e06

Please sign in to comment.