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 = '')
{
// phpcs:enable
global $langs, $conf, $db, $user;
global $langs, $conf, $db, $user, $hookmanager;
$out = '';
$outarray = array();
@ -3179,6 +3179,13 @@ class Form
$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;
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 = '<option value="'.$outkey.'"';
$optstart = '<option value="'.$outkey.'"';
if ($selected && $selected == $objp->idprodfournprice) {
$opt .= ' selected';
$optstart .= ' selected';
}
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
$opt .= ' disabled';
$optstart .= ' disabled';
}
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).'"';
$opt .= ' data-html="'.dol_escape_htmltag($optlabel).'"';
$opt .= '>';
$optstart .= ' data-description="'.dol_escape_htmltag($objp->description, 0, 1).'"';
$opt .= $optlabel;
$outval .= $outvallabel;
$outarrayentry = array(
'key' => $outkey,
'value' => $outref,
'label' => $outvallabel,
'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
);
$opt .= "</option>\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 . "</option>\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 (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"