Little refactor in product/liste.php

This commit is contained in:
Marcos García 2013-12-15 18:49:55 +01:00
parent d65374bb02
commit 290b810bb8

View File

@ -143,47 +143,32 @@ else
{ {
// For natural search // For natural search
$scrit = explode(' ', $sall); $scrit = explode(' ', $sall);
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active foreach ($scrit as $crit) {
{
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)."%'";
$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)) // multilang
{ if ($conf->global->MAIN_MULTILANGS) {
//If the barcode looks like an EAN13 format and the last digit is included in it, $sql .= " OR pl.description LIKE '%".$db->escape($sall)."%' OR pl.note LIKE '%".$db->escape($sall)."%'";
//then whe look for the 12-digit too }
//As the twelve-digit string will also hit the 13-digit code, we only look for this one
//Some code written by "hipnosapo" forum user in http://www.dolibarr.es/index.php/foro/7-bugs-versiones-estables/3891-ean13-buscador-codigo-barras-13-digitos#3891 if (! empty($conf->barcode->enabled))
if (strlen($crit) == 13) { {
$crit_12digit = substr($crit, 0, 12); //If the barcode looks like an EAN13 format and the last digit is included in it,
$sql .= "OR p.barcode LIKE '%".$db->escape($crit_12digit)."%'"; //then whe look for the 12-digit too
} else { //As the twelve-digit string will also hit the 13-digit code, we only look for this one
$sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'"; //Some code written by "hipnosapo" forum user in http://www.dolibarr.es/index.php/foro/7-bugs-versiones-estables/3891-ean13-buscador-codigo-barras-13-digitos#3891
} if (strlen($crit) == 13) {
} $crit_barcode = substr($crit, 0, 12);
$sql.= ')'; } else {
} $crit_barcode = $crit;
} }
else
{ $sql .= " OR p.barcode LIKE '%".$db->escape($crit_barcode)."%'";
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)."%'"; $sql.= ')';
if (! empty($conf->barcode->enabled)) }
{
//If the barcode looks like an EAN13 format and the last digit is included in it,
//then whe look for the 12-digit too
//As the twelve-digit string will also hit the 13-digit code, we only look for this one
//Some code written by "hipnosapo" forum user in http://www.dolibarr.es/index.php/foro/7-bugs-versiones-estables/3891-ean13-buscador-codigo-barras-13-digitos#3891
if (strlen($crit) == 13) {
$crit_12digit = substr($crit, 0, 12);
$sql .= "OR p.barcode LIKE '%".$db->escape($crit_12digit)."%'";
} else {
$sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'";
}
}
$sql.= ')';
}
}
} }
// if the type is not 1, we show all products (type = 0,2,3) // if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type)) if (dol_strlen($type))