Merge pull request #18643 from Gecka-Apps/14-takepos-fast-product-search
TakePos - fast product search
This commit is contained in:
commit
88cd9afe84
@ -42,6 +42,7 @@ if (!defined('NOBROWSERNOTIF')) {
|
|||||||
|
|
||||||
require '../../main.inc.php'; // Load $user and permissions
|
require '../../main.inc.php'; // Load $user and permissions
|
||||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
|
||||||
|
|
||||||
$category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'supplements'
|
$category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'supplements'
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
@ -119,6 +120,24 @@ if ($action == 'getProducts') {
|
|||||||
if ($resql) {
|
if ($resql) {
|
||||||
$rows = array();
|
$rows = array();
|
||||||
while ($obj = $db->fetch_object($resql)) {
|
while ($obj = $db->fetch_object($resql)) {
|
||||||
|
|
||||||
|
$objProd = new Product($db);
|
||||||
|
$objProd->fetch($obj->rowid);
|
||||||
|
$image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity], 'small', 1);
|
||||||
|
|
||||||
|
preg_match('@src="([^"]+)"@', $image, $match);
|
||||||
|
$file = array_pop($match);
|
||||||
|
|
||||||
|
if ($file == "") {
|
||||||
|
$ig = '../public/theme/common/nophoto.png';
|
||||||
|
} else {
|
||||||
|
if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
|
||||||
|
$ig = $file.'&cache=1';
|
||||||
|
} else {
|
||||||
|
$ig = $file.'&cache=1&publictakepos=1&modulepart=product';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
'rowid' => $obj->rowid,
|
'rowid' => $obj->rowid,
|
||||||
'ref' => $obj->ref,
|
'ref' => $obj->ref,
|
||||||
@ -127,7 +146,8 @@ if ($action == 'getProducts') {
|
|||||||
'tobuy' => $obj->tobuy,
|
'tobuy' => $obj->tobuy,
|
||||||
'barcode' => $obj->barcode,
|
'barcode' => $obj->barcode,
|
||||||
'price' => $obj->price,
|
'price' => $obj->price,
|
||||||
'object' => 'product'
|
'object' => 'product',
|
||||||
|
'img' => $ig,
|
||||||
//'price_formated' => price(price2num($obj->price, 'MU'), 1, $langs, 1, -1, -1, $conf->currency)
|
//'price_formated' => price(price2num($obj->price, 'MU'), 1, $langs, 1, -1, -1, $conf->currency)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,6 +178,7 @@ var place="<?php echo $place; ?>";
|
|||||||
var editaction="qty";
|
var editaction="qty";
|
||||||
var editnumber="";
|
var editnumber="";
|
||||||
var invoiceid=0;
|
var invoiceid=0;
|
||||||
|
var search2_timer=null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var app = this;
|
var app = this;
|
||||||
@ -551,62 +552,76 @@ function Search2(keyCodeForEnter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (search === true) {
|
if (search === true) {
|
||||||
pageproducts = 0;
|
|
||||||
jQuery(".wrapper2 .catwatermark").hide();
|
// temporization time to give time to type
|
||||||
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + $('#search').val(), function (data) {
|
if (search2_timer) {
|
||||||
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
|
clearTimeout(search2_timer);
|
||||||
if (typeof (data[i]) == "undefined") {
|
}
|
||||||
$("#prodesc" + i).text("");
|
|
||||||
$("#probutton" + i).text("");
|
search2_timer = setTimeout(function(){
|
||||||
$("#probutton" + i).hide();
|
|
||||||
$("#proprice" + i).attr("class", "hidden");
|
pageproducts = 0;
|
||||||
$("#proprice" + i).html("");
|
jQuery(".wrapper2 .catwatermark").hide();
|
||||||
$("#proimg" + i).attr("src", "genimg/empty.png");
|
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + $('#search').val(), function (data) {
|
||||||
$("#prodiv" + i).data("rowid", "");
|
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
|
||||||
continue;
|
if (typeof (data[i]) == "undefined") {
|
||||||
|
$("#prodesc" + i).text("");
|
||||||
|
$("#probutton" + i).text("");
|
||||||
|
$("#probutton" + i).hide();
|
||||||
|
$("#proprice" + i).attr("class", "hidden");
|
||||||
|
$("#proprice" + i).html("");
|
||||||
|
$("#proimg" + i).attr("src", "genimg/empty.png");
|
||||||
|
$("#prodiv" + i).data("rowid", "");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
<?php
|
||||||
|
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
|
||||||
|
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
|
||||||
|
?>
|
||||||
|
var titlestring = <?php echo $titlestring; ?>;
|
||||||
|
$("#prodesc" + i).text(data[i]['label']);
|
||||||
|
$("#prodivdesc" + i).show();
|
||||||
|
$("#probutton" + i).text(data[i]['label']);
|
||||||
|
$("#probutton" + i).show();
|
||||||
|
if (data[i]['price_formated']) {
|
||||||
|
$("#proprice" + i).attr("class", "productprice");
|
||||||
|
$("#proprice" + i).html(data[i]['price_formated']);
|
||||||
|
}
|
||||||
|
$("#proimg" + i).attr("title", titlestring);
|
||||||
|
if( undefined !== data[i]['img']) {
|
||||||
|
$("#proimg" + i).attr("src", data[i]['img']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
|
||||||
|
}
|
||||||
|
$("#prodiv" + i).data("rowid", data[i]['rowid']);
|
||||||
|
$("#prodiv" + i).data("iscat", 0);
|
||||||
}
|
}
|
||||||
<?php
|
}).always(function (data) {
|
||||||
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
|
// If there is only 1 answer
|
||||||
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
|
if ($('#search').val().length > 0 && data.length == 1) {
|
||||||
?>
|
console.log($('#search').val()+' - '+data[0]['barcode']);
|
||||||
var titlestring = <?php echo $titlestring; ?>;
|
if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
|
||||||
$("#prodesc" + i).text(data[i]['label']);
|
console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
|
||||||
$("#prodivdesc" + i).show();
|
ChangeThirdparty(data[0]['rowid']);
|
||||||
$("#probutton" + i).text(data[i]['label']);
|
}
|
||||||
$("#probutton" + i).show();
|
else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
|
||||||
if (data[i]['price_formated']) {
|
console.log("There is only 1 answer with barcode matching the search, so we add the product in basket");
|
||||||
$("#proprice" + i).attr("class", "productprice");
|
ClickProduct(0);
|
||||||
$("#proprice" + i).html(data[i]['price_formated']);
|
}
|
||||||
}
|
}
|
||||||
$("#proimg" + i).attr("title", titlestring);
|
if (eventKeyCode == keyCodeForEnter){
|
||||||
$("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
|
if (data.length == 0) {
|
||||||
$("#prodiv" + i).data("rowid", data[i]['rowid']);
|
$('#search').val('<?php
|
||||||
$("#prodiv" + i).data("iscat", 0);
|
$langs->load('errors');
|
||||||
}
|
echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
|
||||||
}).always(function (data) {
|
?>');
|
||||||
// If there is only 1 answer
|
$('#search').select();
|
||||||
if ($('#search').val().length > 0 && data.length == 1) {
|
}
|
||||||
console.log($('#search').val()+' - '+data[0]['barcode']);
|
else ClearSearch();
|
||||||
if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
|
|
||||||
console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
|
|
||||||
ChangeThirdparty(data[0]['rowid']);
|
|
||||||
}
|
}
|
||||||
else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
|
});
|
||||||
console.log("There is only 1 answer with barcode matching the search, so we add the product in basket");
|
}, 700); // 700ms delay
|
||||||
ClickProduct(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (eventKeyCode == keyCodeForEnter){
|
|
||||||
if (data.length == 0) {
|
|
||||||
$('#search').val('<?php
|
|
||||||
$langs->load('errors');
|
|
||||||
echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
|
|
||||||
?>');
|
|
||||||
$('#search').select();
|
|
||||||
}
|
|
||||||
else ClearSearch();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user