Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new variable search_term to be more clear #32042

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -744,7 +744,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
Loading