From de37c01bfab8c875bcb7d46f82d3f46190334150 Mon Sep 17 00:00:00 2001 From: kkhelifa Date: Tue, 7 Mar 2023 16:27:25 +0100 Subject: [PATCH 1/2] NEW - Add hook in loadLotStock() in html.formproduct.class.php file --- .../product/class/html.formproduct.class.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index beb84f3e455..14457c312ed 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -865,6 +865,25 @@ class FormProduct // clear cache $this->cache_lot = array(); $productIdList = implode(',', $productIdArray); + + $batch_count = 0; + include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($this->db); + $hookmanager->initHooks(array('productdao')); + $parameters = array('productIdList' => $productIdList); + $reshook = $hookmanager->executeHooks('loadLotStock', $parameters, $this); + if ($reshook < 0) { + $this->error = $hookmanager->error; + return -1; + } + if (!empty($hookmanager->resArray['batch_list']) && is_array($hookmanager->resArray['batch_list'])) { + $this->cache_lot = $hookmanager->resArray['batch_list']; + $batch_count = (int) $hookmanager->resArray['batch_count']; + } + if ($reshook > 0) { + return $batch_count; + } + $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product"; $sql .= " FROM ".$this->db->prefix()."product_batch as pb"; $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock"; @@ -889,7 +908,7 @@ class FormProduct $i++; } - return $num; + return $batch_count + $num; } else { dol_print_error($this->db); return -1; From 6860325f96f1abf5c936a005198edbb171caa8ad Mon Sep 17 00:00:00 2001 From: kkhelifa Date: Thu, 30 Mar 2023 11:13:17 +0200 Subject: [PATCH 2/2] Correction --- htdocs/product/class/html.formproduct.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index 14457c312ed..f9ea6b54beb 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -867,8 +867,11 @@ class FormProduct $productIdList = implode(',', $productIdArray); $batch_count = 0; - include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); + global $hookmanager; + if (empty($hookmanager)) { + include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($this->db); + } $hookmanager->initHooks(array('productdao')); $parameters = array('productIdList' => $productIdList); $reshook = $hookmanager->executeHooks('loadLotStock', $parameters, $this);