NEW: hook to modify supplier product html select

This commit is contained in:
Marc de Lima Lucio 2022-07-18 17:29:49 +02:00
parent dfb5bb0936
commit 53812c9f13

View File

@ -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 = '') 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 // phpcs:enable
global $langs, $conf, $db, $user; global $langs, $conf, $db, $user, $hookmanager;
$out = ''; $out = '';
$outarray = array(); $outarray = array();
@ -3179,6 +3179,13 @@ class Form
$out .= '<option value="-1">'.($placeholder ? $placeholder : '&nbsp;').'</option>'; $out .= '<option value="-1">'.($placeholder ? $placeholder : '&nbsp;').'</option>';
} }
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; $i = 0;
while ($i < $num) { while ($i < $num) {
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
@ -3189,7 +3196,6 @@ class Form
} }
$outref = $objp->ref; $outref = $objp->ref;
$outval = '';
$outbarcode = $objp->barcode; $outbarcode = $objp->barcode;
$outqty = 1; $outqty = 1;
$outdiscount = 0; $outdiscount = 0;
@ -3370,35 +3376,22 @@ class Form
} }
} }
$opt = '<option value="'.$outkey.'"'; $optstart = '<option value="'.$outkey.'"';
if ($selected && $selected == $objp->idprodfournprice) { if ($selected && $selected == $objp->idprodfournprice) {
$opt .= ' selected'; $optstart .= ' selected';
} }
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) { if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
$opt .= ' disabled'; $optstart .= ' disabled';
} }
if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) { if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
$opt .= ' data-qty="'.$objp->quantity.'" data-up="'.$objp->unitprice.'" data-discount="'.$outdiscount.'"'; $optstart .= ' data-qty="'.$objp->quantity.'" data-up="'.$objp->unitprice.'" data-discount="'.$outdiscount.'"';
} }
$opt .= ' data-description="'.dol_escape_htmltag($objp->description, 0, 1).'"'; $optstart .= ' data-description="'.dol_escape_htmltag($objp->description, 0, 1).'"';
$opt .= ' data-html="'.dol_escape_htmltag($optlabel).'"';
$opt .= '>';
$opt .= $optlabel; $outarrayentry = array(
$outval .= $outvallabel; 'key' => $outkey,
$opt .= "</option>\n";
// 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, 'value' => $outref,
'label'=>$outval, 'label' => $outvallabel,
'qty' => $outqty, 'qty' => $outqty,
'price_ht' => price2num($objp->unitprice, 'MU'), 'price_ht' => price2num($objp->unitprice, 'MU'),
'discount' => $outdiscount, 'discount' => $outdiscount,
@ -3407,8 +3400,24 @@ class Form
'duration_unit' => $outdurationunit, 'duration_unit' => $outdurationunit,
'disabled' => (empty($objp->idprodfournprice) ? true : false), 'disabled' => (empty($objp->idprodfournprice) ? true : false),
'description' => $objp->description 'description' => $objp->description
)
); );
$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 .= $optstart . ' data-html="'.dol_escape_htmltag($optlabel).'">' . $optlabel . "</option>\n";
array_push($outarray, $outarrayentry);
// Exemple of var_dump $outarray // Exemple of var_dump $outarray
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp" // array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)" // ["label"]=>string(76) "ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"