Merge pull request #982 from FHenry/3.3

Fix search product if multilingue
This commit is contained in:
Laurent Destailleur
2013-05-25 02:01:14 -07:00

View File

@@ -3,7 +3,8 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
*
* Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
* 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))