From 99906ce12773b99504297b604181ec9c27a355bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Nov 2019 14:29:58 +0100 Subject: [PATCH] Fix the root category not used for search from POS --- htdocs/categories/class/categorie.class.php | 2 ++ htdocs/takepos/ajax/ajax.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 56f26eb2dd9..b9d58fc76f1 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1146,11 +1146,13 @@ class Categorie extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * For category id_categ and its childs available in this->cats, define property fullpath and fulllabel. + * It is called by get_full_arbo() * This function is a memory scan only from $this->cats and $this->motherof, no database access must be done here. * * @param int $id_categ id_categ entry to update * @param int $protection Deep counter to avoid infinite loop * @return void + * @see get_full_arbo() */ public function build_path_from_id_categ($id_categ, $protection = 1000) { diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 236f7750ef7..c6b9f309293 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -66,7 +66,24 @@ if ($action == "getProducts") { } } elseif ($action == "search" && $term != '') { - $sql = 'SELECT rowid, ref, label, tosell, tobuy FROM '.MAIN_DB_PREFIX.'product'; + // Define $filteroncategids, the filter on category ID if there is a Root category defined. + $filteroncategids = ''; + if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) { // A root category is defined, we must filter on products inside this category tree + $object = new Categorie($db); + //$result = $object->fetch($conf->global->TAKEPOS_ROOT_CATEGORY_ID); + $arrayofcateg = $object->get_full_arbo('product', $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 1); + if (is_array($arrayofcateg) && count($arrayofcateg) > 0) { + foreach($arrayofcateg as $val) + { + $filteroncategids .= ($filteroncategids ? ', ' : '').$val['id']; + } + } + } + + $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 .= ' AND tosell = 1'; $sql .= natural_search(array('ref', 'label', 'barcode'), $term);