NEW - Add hook in loadLotStock() in html.formproduct.class.php file

This commit is contained in:
kkhelifa 2023-03-07 16:27:25 +01:00
parent c9d869f837
commit de37c01bfa

View File

@ -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;