Uniformize code for search
This commit is contained in:
parent
e53157b28b
commit
7faedf0c69
@ -130,24 +130,28 @@ if ($action == 'search')
|
|||||||
{
|
{
|
||||||
$current_lang = $langs->getDefaultLang();
|
$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';
|
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= ', pl.label as labelm, pl.description as descriptionm';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON p.rowid = cp.fk_product';
|
$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)."'";
|
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 != "")
|
if ($key != "")
|
||||||
{
|
{
|
||||||
|
// For natural search
|
||||||
|
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
|
||||||
|
// multilang
|
||||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||||
{
|
{
|
||||||
$sql.= " AND (p.ref LIKE '%".$key."%'";
|
$params[] = 'pl.label';
|
||||||
$sql.= " OR pl.label LIKE '%".$key."%')";
|
$params[] = 'pl.description';
|
||||||
|
$params[] = 'pl.note';
|
||||||
}
|
}
|
||||||
else
|
if (! empty($conf->barcode->enabled)) {
|
||||||
{
|
$params[] = 'p.barcode';
|
||||||
$sql.= " AND (p.ref LIKE '%".$key."%'";
|
|
||||||
$sql.= " OR p.label LIKE '%".$key."%')";
|
|
||||||
}
|
}
|
||||||
|
$sql .= natural_search($params, $key);
|
||||||
}
|
}
|
||||||
if (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1)
|
if (! empty($conf->categorie->enabled) && ! empty($parent) && $parent != -1)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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 = '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.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.= ' MIN(pfp.unitprice) as minsellprice';
|
||||||
$sql .= ', p.desiredstock';
|
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
|
$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
|
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";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
|
||||||
// multilang
|
// multilang
|
||||||
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
|
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 .= " 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).')';
|
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
|
||||||
if ($sall)
|
if ($sall)
|
||||||
{
|
{
|
||||||
// For natural search
|
// For natural search
|
||||||
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
|
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
|
||||||
// multilang
|
// 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.description';
|
||||||
$params[] = 'pl.note';
|
$params[] = 'pl.note';
|
||||||
}
|
}
|
||||||
@ -169,7 +166,7 @@ else
|
|||||||
{
|
{
|
||||||
$params = array('p.label');
|
$params = array('p.label');
|
||||||
// multilang
|
// multilang
|
||||||
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
|
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||||
{
|
{
|
||||||
$params[] = 'pl.label';
|
$params[] = 'pl.label';
|
||||||
}
|
}
|
||||||
@ -199,7 +196,6 @@ else
|
|||||||
$sql.= $db->order($sortfield,$sortorder);
|
$sql.= $db->order($sortfield,$sortorder);
|
||||||
$sql.= $db->plimit($limit + 1, $offset);
|
$sql.= $db->plimit($limit + 1, $offset);
|
||||||
|
|
||||||
dol_syslog("product:list.php:", LOG_DEBUG);
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user