FIX avoid Unknown column 'pfp.ref_fourn' (#28145)

This commit is contained in:
Regis Houssin 2024-02-15 16:47:07 +01:00 committed by GitHub
parent 280ceef46b
commit 1ef91d3a21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -432,7 +432,21 @@ if (!empty($conf->global->PRODUCT_USE_UNITS)) {
$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
if ($sall) {
$sql .= natural_search(array_keys($fieldstosearchall), $sall);
// Clean $fieldstosearchall
$newfieldstosearchall = $fieldstosearchall;
unset($newfieldstosearchall['pfp.ref_fourn']);
unset($newfieldstosearchall['pfp.barcode']);
$sql .= ' AND (';
$sql .= natural_search(array_keys($newfieldstosearchall), $sall, 0, 1);
// Search also into a supplier reference 'pfp.ref_fourn'="RefSupplier"
$sql .= ' OR EXISTS (SELECT rowid FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid';
$sql .= ' AND ('.natural_search('pfp.ref_fourn', $sall, 0, 1);
if (isModEnabled('barcode')) {
// Search also into a supplier barcode 'pfp.barcode'='GencodBuyPrice';
$sql .= ' OR '.natural_search('pfp.barcode', $sall, 0, 1);
}
$sql .= ')))';
}
// if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($search_type) && $search_type != '-1') {