diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index beb84f3e455..f9ea6b54beb 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -865,6 +865,28 @@ class FormProduct // clear cache $this->cache_lot = array(); $productIdList = implode(',', $productIdArray); + + $batch_count = 0; + 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); + 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 +911,7 @@ class FormProduct $i++; } - return $num; + return $batch_count + $num; } else { dol_print_error($this->db); return -1;