From fd64b3baec67c462786d61bbacb0a219a27cf31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20de=20Grandpr=C3=A9?= Date: Sat, 13 Aug 2022 18:32:30 -0400 Subject: [PATCH 1/4] =?UTF-8?q?CLOSE=2021748=20Maillage=20sur=20ErrorProdu?= =?UTF-8?q?ctAlreadyExists=20en=20cr=C3=A9ant=20produit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/product/card.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 9137a3b7c10..a87920c43f2 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -19,6 +19,7 @@ * Copyright (C) 2019-2022 Frédéric France * Copyright (C) 2019-2020 Thibault FOUCART * Copyright (C) 2020 Pierre Ardoin + * Copyright (C) 2022 Vincent de Grandpré * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -666,7 +667,20 @@ if (empty($reshook)) { if (count($object->errors)) { setEventMessages($object->error, $object->errors, 'errors'); } else { - setEventMessages($langs->trans($object->error), null, 'errors'); + if($object->error == 'ErrorProductAlreadyExists') { + // permet une action personnallisée quand il y a tentative d'ajouter un produit + // avec un numéro de référence existant. + $reshook = $hookmanager->executeHooks('onProductAlreadyExists', $parameters, $object, $action); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + if($object->error) { + // L'erreur de l'objet a pu être effacée par la fonction + setEventMessages($langs->trans($object->error), null, 'errors'); + } + } else { + setEventMessages($langs->trans($object->error), null, 'errors'); + } } $action = "create"; } From 142f2422675bf3d9872b6a666a150f5ab0f278b9 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 13 Aug 2022 22:35:53 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/product/card.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a87920c43f2..c192b29eb7e 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -667,16 +667,16 @@ if (empty($reshook)) { if (count($object->errors)) { setEventMessages($object->error, $object->errors, 'errors'); } else { - if($object->error == 'ErrorProductAlreadyExists') { - // permet une action personnallisée quand il y a tentative d'ajouter un produit + if ($object->error == 'ErrorProductAlreadyExists') { + // permet une action personnallisée quand il y a tentative d'ajouter un produit // avec un numéro de référence existant. $reshook = $hookmanager->executeHooks('onProductAlreadyExists', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - if($object->error) { + } + if ($object->error) { // L'erreur de l'objet a pu être effacée par la fonction - setEventMessages($langs->trans($object->error), null, 'errors'); + setEventMessages($langs->trans($object->error), null, 'errors'); } } else { setEventMessages($langs->trans($object->error), null, 'errors'); From 7a22e6f33961fb1b5d199d824b2cd49bbac6f551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20de=20Grandpr=C3=A9?= Date: Sun, 14 Aug 2022 09:48:49 -0400 Subject: [PATCH 3/4] commentaires du code en anglais --- htdocs/product/card.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index c192b29eb7e..42b3ee1ec9c 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -668,14 +668,14 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } else { if ($object->error == 'ErrorProductAlreadyExists') { - // permet une action personnallisée quand il y a tentative d'ajouter un produit - // avec un numéro de référence existant. + // allow to hook on ErrorProductAlreadyExists in any module $reshook = $hookmanager->executeHooks('onProductAlreadyExists', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if ($object->error) { - // L'erreur de l'objet a pu être effacée par la fonction + // check again to prevent translation issue, + // as error may have been cleared in hook function setEventMessages($langs->trans($object->error), null, 'errors'); } } else { From 6c1289382c1660f6056f7952403056583174700c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 14 Aug 2022 13:49:28 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/product/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 42b3ee1ec9c..d4baa9870ff 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -674,7 +674,7 @@ if (empty($reshook)) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if ($object->error) { - // check again to prevent translation issue, + // check again to prevent translation issue, // as error may have been cleared in hook function setEventMessages($langs->trans($object->error), null, 'errors'); }