Takepos: set proper image directly when searching products

Bypasses genimg/index.php that either redirects to viewimage.php or to nophoto.png. That was making lots of request to the server and excessive load on the database server, that queues them slowing down the UI.
This commit is contained in:
Laurent Dinclaux 2021-09-08 00:02:27 +11:00
parent 10780a343e
commit 303313b168
2 changed files with 28 additions and 3 deletions

View File

@ -42,6 +42,7 @@ if (!defined('NOBROWSERNOTIF')) {
require '../../main.inc.php'; // Load $user and permissions
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'
$action = GETPOST('action', 'aZ09');
@ -119,6 +120,25 @@ if ($action == 'getProducts') {
if ($resql) {
$rows = array();
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(
'rowid' => $obj->rowid,
'ref' => $obj->ref,
@ -127,7 +147,8 @@ if ($action == 'getProducts') {
'tobuy' => $obj->tobuy,
'barcode' => $obj->barcode,
'price' => $obj->price,
'object' => 'product'
'object' => 'product',
'img' => $ig,
//'price_formated' => price(price2num($obj->price, 'MU'), 1, $langs, 1, -1, -1, $conf->currency)
);
}

View File

@ -549,7 +549,6 @@ function Search2(keyCodeForEnter) {
// temporization time to give time to type
if (search2_timer) {
console.log(search2_timer);
clearTimeout(search2_timer);
}
@ -583,7 +582,12 @@ function Search2(keyCodeForEnter) {
$("#proprice" + i).html(data[i]['price_formated']);
}
$("#proimg" + i).attr("title", titlestring);
$("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
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);
}