From 28833e71a156189143233b1ecf97e3c68bf3a3f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 17 Nov 2022 12:39:24 +0100 Subject: [PATCH] FIX for #22882 --- htdocs/product/fournisseurs.php | 9 ++++++--- htdocs/product/list.php | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 5eae5c45dc9..8345839dae1 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -270,10 +270,13 @@ if (empty($reshook)) { if ($ret == -3) { $error++; - $object->fetch($object->product_id_already_linked); - $productLink = $object->getNomUrl(1, 'supplier'); + $tmpobject = new Product($db); + $tmpobject->fetch($object->product_id_already_linked); + $productLink = $tmpobject->getNomUrl(1, 'supplier'); - setEventMessages($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct", $productLink), null, 'errors'); + $texttoshow = $langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct", '{s1}'); + $texttoshow = str_replace('{s1}', $productLink, $texttoshow); + setEventMessages($texttoshow, null, 'errors'); } elseif ($ret < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 5716c1a70ea..b96a0f6447e 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -176,7 +176,6 @@ if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'p.ref'=>"Ref", - 'pfp.ref_fourn'=>"RefSupplier", 'p.label'=>"ProductLabel", 'p.description'=>"Description", "p.note"=>"Note", @@ -190,7 +189,6 @@ if (getDolGlobalInt('MAIN_MULTILANGS')) { } if (isModEnabled('barcode')) { $fieldstosearchall['p.barcode'] = 'Gencod'; - $fieldstosearchall['pfp.barcode'] = 'GencodBuyPrice'; } // Personalized search criterias. Example: $conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS = 'p.ref=ProductRef;p.label=ProductLabel;p.description=Description;p.note=Note;' if (!empty($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS)) { @@ -459,7 +457,16 @@ if (!empty($conf->global->PRODUCT_USE_UNITS)) { $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if ($sall) { - $sql .= natural_search(array_keys($fieldstosearchall), $sall); + $sql .= ' AND ('; + $sql .= natural_search(array_keys($fieldstosearchall), $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') {