Merge pull request #24279 from Easya-Solutions/new-takepos-limit-load-products

NEW limit load products in takepos
This commit is contained in:
Laurent Destailleur 2023-03-20 16:07:18 +01:00 committed by GitHub
commit b76ee6d385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 20 deletions

View File

@ -845,10 +845,12 @@ class Categorie extends CommonObject
* @param int $offset Offset
* @param string $sortfield Sort fields
* @param string $sortorder Sort order ('ASC' or 'DESC');
* @param array $filter Filter array. Example array('field'=>'valueforlike', 'customsql'=>...)
* @param string $filtermode Filter mode (AND or OR)
* @return array|int -1 if KO, array of instance of object if OK
* @see containsObject()
*/
public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC')
public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC', $filter = array(), $filtermode = 'AND')
{
global $user;
@ -867,10 +869,24 @@ class Categorie extends CommonObject
if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) {
$sql .= " AND o.rowid = ".((int) $user->socid);
}
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key == 'o.rowid') {
$sqlwhere[] = $key." = ".((int) $value);
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
}
}
}
if (count($sqlwhere) > 0) {
$sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
}
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit > 0 || $offset > 0) {
$sql .= $this->db->plimit($limit + 1, $offset);
}
$sql .= $this->db->order($sortfield, $sortorder);
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
$resql = $this->db->query($sql);

View File

@ -62,6 +62,10 @@ $hookmanager->initHooks(array('takeposproductsearch')); // new context for produ
*/
if ($action == 'getProducts') {
$tosell = GETPOSTISSET('tosell') ? GETPOST('tosell', 'int') : '';
$limit = GETPOSTISSET('limit') ? GETPOST('limit', 'int') : 0;
$offset = GETPOSTISSET('offset') ? GETPOST('offset', 'int') : 0;
top_httphead('application/json');
$object = new Categorie($db);
@ -70,7 +74,11 @@ if ($action == 'getProducts') {
}
$result = $object->fetch($category);
if ($result > 0) {
$prods = $object->getObjectsInCateg("product", 0, 0, 0, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC');
$filter = array();
if ($tosell != '') {
$filter = array('customsql' => 'o.tosell = '.((int) $tosell));
}
$prods = $object->getObjectsInCateg("product", 0, $limit, $offset, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC', $filter);
// Removed properties we don't need
$res = array();
if (is_array($prods) && count($prods) > 0) {

View File

@ -322,7 +322,12 @@ function LoadProducts(position, issubcat) {
});
idata=0; //product data counter
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat, function(data) {
var limit = 0;
if (maxproduct >= 1) {
limit = maxproduct-1;
}
// Only show products for sale (tosell=1)
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat+'&tosell=1&limit='+limit+'&offset=0', function(data) {
console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
console.log(data);
while (ishow < maxproduct) {
@ -342,10 +347,7 @@ function LoadProducts(position, issubcat) {
$("#proprice"+ishow).html("");
$("#prodiv"+ishow).data("rowid","");
$("#prodiv"+ishow).attr("class","wrapper2 divempty");
$("#prowatermark"+ishow).hide();
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell)
} else {
<?php
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
@ -376,8 +378,7 @@ function LoadProducts(position, issubcat) {
console.log($('#prodiv4').data('rowid'));
$("#prodiv"+ishow).data("iscat", 0);
$("#prodiv"+ishow).attr("class","wrapper2");
$("#prowatermark"+ishow).hide();
ishow++; //Next product to show after print data product
<?php
// Add js from hooks
$parameters=array();
@ -386,7 +387,8 @@ function LoadProducts(position, issubcat) {
print $hookmanager->resPrint;
?>
}
//console.log("Hide the prowatermark for ishow="+ishow);
$("#prowatermark"+ishow).hide();
ishow++; //Next product to show after print data product
idata++; //Next data everytime
}
});
@ -414,15 +416,22 @@ function MoreProducts(moreorless) {
if (pageproducts==0) return; //Return if no less pages
pageproducts=pageproducts-1;
}
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat, function(data) {
ishow=0; //product to show counter
idata=0; //product data counter
var limit = 0;
if (maxproduct >= 1) {
limit = maxproduct-1;
}
var offset = <?php echo ($MAXPRODUCT - 2); ?> * pageproducts;
// Only show products for sale (tosell=1)
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat+'&tosell=1&limit='+limit+'&offset='+offset, function(data) {
console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
if (typeof (data[(maxproduct * pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
if (typeof (data[0]) == "undefined" && moreorless=="more"){ // Return if no more pages
pageproducts=pageproducts-1;
return;
}
idata=<?php echo ($MAXPRODUCT - 2); ?> * pageproducts; //product data counter
ishow=0; //product to show counter
while (ishow < maxproduct) {
if (typeof (data[idata]) == "undefined") {
@ -434,10 +443,7 @@ function MoreProducts(moreorless) {
$("#proprice"+ishow).html("");
$("#proimg"+ishow).attr("src","genimg/empty.png");
$("#prodiv"+ishow).data("rowid","");
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") {
//Only show products with status=1 (for sell)
} else {
$("#prodivdesc"+ishow).show();
<?php
if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
@ -454,9 +460,9 @@ function MoreProducts(moreorless) {
$("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
$("#prodiv"+ishow).data("iscat",0);
ishow++; //Next product to show after print data product
}
$("#prowatermark"+ishow).hide();
ishow++; //Next product to show after print data product
idata++; //Next data everytime
}
});