Fix avoid duplicate product when searching on product with n categories
This commit is contained in:
parent
d5f11a5b88
commit
9754158756
@ -43,7 +43,7 @@ $id = GETPOST('id', 'int');
|
|||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($action == "getProducts") {
|
if ($action == 'getProducts') {
|
||||||
$object = new Categorie($db);
|
$object = new Categorie($db);
|
||||||
$result = $object->fetch($category);
|
$result = $object->fetch($category);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
@ -65,7 +65,7 @@ if ($action == "getProducts") {
|
|||||||
echo 'Failed to load category with id='.$category;
|
echo 'Failed to load category with id='.$category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($action == "search" && $term != '') {
|
elseif ($action == 'search' && $term != '') {
|
||||||
// Define $filteroncategids, the filter on category ID if there is a Root category defined.
|
// Define $filteroncategids, the filter on category ID if there is a Root category defined.
|
||||||
$filteroncategids = '';
|
$filteroncategids = '';
|
||||||
if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) { // A root category is defined, we must filter on products inside this category tree
|
if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) { // A root category is defined, we must filter on products inside this category tree
|
||||||
@ -81,10 +81,10 @@ elseif ($action == "search" && $term != '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'SELECT rowid, ref, label, tosell, tobuy FROM '.MAIN_DB_PREFIX.'product as p';
|
$sql = 'SELECT rowid, ref, label, tosell, tobuy FROM '.MAIN_DB_PREFIX.'product as p';
|
||||||
if ($filteroncategids) {
|
|
||||||
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid AND cp.fk_categorie IN ('.$filteroncategids.')';
|
|
||||||
}
|
|
||||||
$sql .= ' WHERE entity IN ('.getEntity('product').')';
|
$sql .= ' WHERE entity IN ('.getEntity('product').')';
|
||||||
|
if ($filteroncategids) {
|
||||||
|
$sql.= ' AND rowid IN (SELECT DISTINCT fk_product FROM '.MAIN_DB_PREFIX.'categorie_product WHERE fk_categorie IN ('.$filteroncategids.'))';
|
||||||
|
}
|
||||||
$sql .= ' AND tosell = 1';
|
$sql .= ' AND tosell = 1';
|
||||||
$sql .= natural_search(array('ref', 'label', 'barcode'), $term);
|
$sql .= natural_search(array('ref', 'label', 'barcode'), $term);
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user