From 53812c9f13ff1d152abc0e9306bd6610fc654a3e Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Mon, 18 Jul 2022 17:29:49 +0200
Subject: [PATCH] NEW: hook to modify supplier product html select
---
htdocs/core/class/html.form.class.php | 65 +++++++++++++++------------
1 file changed, 37 insertions(+), 28 deletions(-)
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 9c14bfeb866..b03aec90908 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3078,7 +3078,7 @@ class Form
public function select_produits_fournisseurs_list($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $filterkey = '', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = '', $showstockinlist = 0, $placeholder = '')
{
// phpcs:enable
- global $langs, $conf, $db, $user;
+ global $langs, $conf, $db, $user, $hookmanager;
$out = '';
$outarray = array();
@@ -3179,6 +3179,13 @@ class Form
$out .= '';
}
+ if (! is_object($hookmanager)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
+ $hookmanager = new HookManager($this->db);
+ }
+
+ $hookmanager->initHooks(array('form'));
+
$i = 0;
while ($i < $num) {
$objp = $this->db->fetch_object($result);
@@ -3189,7 +3196,6 @@ class Form
}
$outref = $objp->ref;
- $outval = '';
$outbarcode = $objp->barcode;
$outqty = 1;
$outdiscount = 0;
@@ -3370,45 +3376,48 @@ class Form
}
}
- $opt = '\n";
+ $parameters = array(
+ 'objp' => &$objp,
+ 'optstart' => &$optstart,
+ 'optlabel' => &$optlabel,
+ 'outvallabel' => &$outvallabel,
+ 'outarrayentry' => &$outarrayentry
+ );
+ $reshook = $hookmanager->executeHooks('selectProduitsFournisseurListOption', $parameters, $this);
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value. Example: 'type' = product or service, 'price_ht' = unit price without tax
// "label" value of json key array is used by jQuery automatically as text for combo box
- $out .= $opt;
- array_push(
- $outarray,
- array('key'=>$outkey,
- 'value'=>$outref,
- 'label'=>$outval,
- 'qty'=>$outqty,
- 'price_ht'=>price2num($objp->unitprice, 'MU'),
- 'discount'=>$outdiscount,
- 'type'=>$outtype,
- 'duration_value'=>$outdurationvalue,
- 'duration_unit'=>$outdurationunit,
- 'disabled'=>(empty($objp->idprodfournprice) ? true : false),
- 'description'=>$objp->description
- )
- );
+ $out .= $optstart . ' data-html="'.dol_escape_htmltag($optlabel).'">' . $optlabel . "\n";
+ array_push($outarray, $outarrayentry);
+
// Exemple of var_dump $outarray
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (fff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"