From 5b02a3a67c804101ea3b8cb81a4e8c9dd58c04e0 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Fri, 24 May 2013 22:44:26 +0200 Subject: [PATCH] Fix search product if multilingue --- htdocs/product/liste.php | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 1a7cba82d68..0204098773b 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -3,7 +3,8 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos GarcĂ­a - * + * Copyright (C) 2013 Jean Heimburger + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or @@ -129,15 +130,39 @@ else $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; +// multilang + if ($conf->global->MAIN_MULTILANGS) // si l'option est active + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$langs->getDefaultLang() ."'"; + } $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; if ($sall) { - $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%'"; - if (! empty($conf->barcode->enabled)) - { - $sql.= " OR p.barcode LIKE '%".$db->escape($sall)."%'"; - } - $sql.= ')'; + // For natural search + $scrit = explode(' ', $sall); + // multilang + if ($conf->global->MAIN_MULTILANGS) // si l'option est active + { + foreach ($scrit as $crit) { + $sql.= " AND (p.ref LIKE '%".$db->escape($crit)."%' OR p.label LIKE '%".$db->escape($crit)."%' OR p.description LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%' OR pl.description LIKE '%".$db->escape($sall)."%' OR pl.note LIKE '%".$db->escape($sall)."%'"; + if (! empty($conf->barcode->enabled)) + { + $sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'"; + } + $sql.= ')'; + } + } + else + { + foreach ($scrit as $crit) { + $sql.= " AND (p.ref LIKE '%".$db->escape($crit)."%' OR p.label LIKE '%".$db->escape($crit)."%' OR p.description LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%'"; + if (! empty($conf->barcode->enabled)) + { + $sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'"; + } + $sql.= ')'; + } + } } // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type))