Skip to content

Commit

Permalink
Merge pull request Dolibarr#32042 from rycks/develop_takepos_search_t…
Browse files Browse the repository at this point in the history
…erm_is_not_same_as_term_variable

new variable search_term to be more clear
  • Loading branch information
eldy authored Feb 12, 2025
2 parents 966cfeb + 1fc7bc2 commit 7bb331f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions htdocs/takepos/ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
$category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'supplements'
$action = GETPOST('action', 'aZ09');
$term = GETPOST('term', 'alpha');
$search_term = GETPOST('search_term', 'alpha');
$id = GETPOSTINT('id');
$search_start = GETPOSTINT('search_start');
$search_limit = GETPOSTINT('search_limit');
Expand Down Expand Up @@ -130,11 +131,11 @@
} else {
echo 'Failed to load category with id='.dol_escape_htmltag($category);
}
} elseif ($action == 'search' && $term != '' && $user->hasRight('takepos', 'run')) {
} elseif ($action == 'search' && $search_term != '' && $user->hasRight('takepos', 'run')) {
top_httphead('application/json');

// Search barcode into thirdparties. If found, it means we want to change thirdparties.
$result = $thirdparty->fetch('', '', '', $term);
$result = $thirdparty->fetch('', '', '', $search_term);

if ($result && $thirdparty->id > 0) {
$rows = array();
Expand Down Expand Up @@ -187,15 +188,15 @@

$barcode_value_list = array();
$barcode_offset = 0;
$barcode_length = dol_strlen($term);
$barcode_length = dol_strlen($search_term);
if ($barcode_length == $barcode_char_nb) {
$rows = array();

// split term with barcode rules
foreach ($barcode_rules_list as $barcode_rule_arr) {
$code = $barcode_rule_arr['code'];
$char_nb = $barcode_rule_arr['char_nb'];
$barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
$barcode_value_list[$code] = substr($search_term, $barcode_offset, $char_nb);
$barcode_offset += $char_nb;
}

Expand All @@ -209,7 +210,7 @@
$sql .= " AND EXISTS (SELECT cp.fk_product FROM " . $db->prefix() . "categorie_product as cp WHERE cp.fk_product = p.rowid AND cp.fk_categorie IN (".$db->sanitize($filteroncategids)."))";
}
$sql .= " AND tosell = 1";
$sql .= " AND (barcode IS NULL OR barcode <> '" . $db->escape($term) . "')";
$sql .= " AND (barcode IS NULL OR barcode <> '" . $db->escape($search_term) . "')";

$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) == 1) {
Expand Down Expand Up @@ -249,7 +250,7 @@
'label' => $obj->label,
'tosell' => $obj->tosell,
'tobuy' => $obj->tobuy,
'barcode' => $term, // there is only one product matches the barcode rule and so the term is considered as the barcode of this product
'barcode' => $search_term, // there is only one product matches the barcode rule and so the term is considered as the barcode of this product
'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
'object' => 'product',
Expand Down Expand Up @@ -317,7 +318,7 @@
if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1 && getDolGlobalInt('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) {
$sql .= ' AND ps.reel > 0';
}
$sql .= natural_search(array('ref', 'label', 'barcode'), $term);
$sql .= natural_search(array('ref', 'label', 'barcode'), $search_term);
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/takepos/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ function Search2(keyCodeForEnter, moreorless) {
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
var nbsearchresults = 0;
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&search_term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#prowatermark" + i).html("");
Expand Down

0 comments on commit 7bb331f

Please sign in to comment.