Uniformize code for search

This commit is contained in:
Laurent Destailleur 2014-11-15 11:59:02 +01:00
parent e53157b28b
commit 7faedf0c69
2 changed files with 17 additions and 17 deletions

View File

@ -130,24 +130,28 @@ if ($action == 'search')
{
$current_lang = $langs->getDefaultLang();
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.price, p.fk_product_type as type';
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
$sql.= ' p.fk_product_type, p.tms as datem';
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= ', pl.label as labelm, pl.description as descriptionm';
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product';
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND lang='".($current_lang)."'";
$sql.= ' WHERE p.entity IN ('.getEntity("product", 1).')';
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
if ($key != "")
{
// For natural search
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
// multilang
if (! empty($conf->global->MAIN_MULTILANGS))
{
$sql.= " AND (p.ref LIKE '%".$key."%'";
$sql.= " OR pl.label LIKE '%".$key."%')";
$params[] = 'pl.label';
$params[] = 'pl.description';
$params[] = 'pl.note';
}
else
{
$sql.= " AND (p.ref LIKE '%".$key."%'";
$sql.= " OR p.label LIKE '%".$key."%')";
if (! empty($conf->barcode->enabled)) {
$params[] = 'p.barcode';
}
$sql .= natural_search($params, $key);
}
if (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1)
{

View File

@ -130,25 +130,22 @@ else
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
$sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
$sql.= ' MIN(pfp.unitprice) as minsellprice';
$sql .= ', p.desiredstock';
$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() ."'";
}
if (! empty($conf->global->MAIN_MULTILANGS)) $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)
{
// For natural search
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
if (! empty($conf->global->MAIN_MULTILANGS))
{
$params[] = 'pl.label';
$params[] = 'pl.description';
$params[] = 'pl.note';
}
@ -169,7 +166,7 @@ else
{
$params = array('p.label');
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
if (! empty($conf->global->MAIN_MULTILANGS))
{
$params[] = 'pl.label';
}
@ -199,7 +196,6 @@ else
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
dol_syslog("product:list.php:", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{