From 1ef91d3a2184a2f5edff5631f4e4193308d0c471 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 15 Feb 2024 16:47:07 +0100 Subject: [PATCH] FIX avoid Unknown column 'pfp.ref_fourn' (#28145) --- htdocs/product/list.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 4f30e146f56..db58e7bfa0d 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -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') {