NEW limit load products in takepos
This commit is contained in:
parent
3c123db60d
commit
d523f91a29
@ -845,6 +845,8 @@ class Categorie extends CommonObject
|
|||||||
* @param int $offset Offset
|
* @param int $offset Offset
|
||||||
* @param string $sortfield Sort fields
|
* @param string $sortfield Sort fields
|
||||||
* @param string $sortorder Sort order ('ASC' or 'DESC');
|
* @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
|
* @return array|int -1 if KO, array of instance of object if OK
|
||||||
* @see containsObject()
|
* @see containsObject()
|
||||||
*/
|
*/
|
||||||
@ -867,10 +869,24 @@ class Categorie extends CommonObject
|
|||||||
if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) {
|
if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) {
|
||||||
$sql .= " AND o.rowid = ".((int) $user->socid);
|
$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) {
|
if ($limit > 0 || $offset > 0) {
|
||||||
$sql .= $this->db->plimit($limit + 1, $offset);
|
$sql .= $this->db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
$sql .= $this->db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
|
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|||||||
@ -62,6 +62,10 @@ $hookmanager->initHooks(array('takeposproductsearch')); // new context for produ
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if ($action == 'getProducts') {
|
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');
|
top_httphead('application/json');
|
||||||
|
|
||||||
$object = new Categorie($db);
|
$object = new Categorie($db);
|
||||||
@ -70,7 +74,11 @@ if ($action == 'getProducts') {
|
|||||||
}
|
}
|
||||||
$result = $object->fetch($category);
|
$result = $object->fetch($category);
|
||||||
if ($result > 0) {
|
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');
|
||||||
// Removed properties we don't need
|
// Removed properties we don't need
|
||||||
$res = array();
|
$res = array();
|
||||||
if (is_array($prods) && count($prods) > 0) {
|
if (is_array($prods) && count($prods) > 0) {
|
||||||
|
|||||||
@ -322,7 +322,12 @@ function LoadProducts(position, issubcat) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
idata=0; //product data counter
|
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("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
|
||||||
console.log(data);
|
console.log(data);
|
||||||
while (ishow < maxproduct) {
|
while (ishow < maxproduct) {
|
||||||
@ -342,10 +347,7 @@ function LoadProducts(position, issubcat) {
|
|||||||
$("#proprice"+ishow).html("");
|
$("#proprice"+ishow).html("");
|
||||||
$("#prodiv"+ishow).data("rowid","");
|
$("#prodiv"+ishow).data("rowid","");
|
||||||
$("#prodiv"+ishow).attr("class","wrapper2 divempty");
|
$("#prodiv"+ishow).attr("class","wrapper2 divempty");
|
||||||
$("#prowatermark"+ishow).hide();
|
} else {
|
||||||
ishow++; //Next product to show after print data product
|
|
||||||
}
|
|
||||||
else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell)
|
|
||||||
<?php
|
<?php
|
||||||
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
|
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
|
||||||
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
|
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
|
||||||
@ -376,8 +378,7 @@ function LoadProducts(position, issubcat) {
|
|||||||
console.log($('#prodiv4').data('rowid'));
|
console.log($('#prodiv4').data('rowid'));
|
||||||
$("#prodiv"+ishow).data("iscat", 0);
|
$("#prodiv"+ishow).data("iscat", 0);
|
||||||
$("#prodiv"+ishow).attr("class","wrapper2");
|
$("#prodiv"+ishow).attr("class","wrapper2");
|
||||||
$("#prowatermark"+ishow).hide();
|
|
||||||
ishow++; //Next product to show after print data product
|
|
||||||
<?php
|
<?php
|
||||||
// Add js from hooks
|
// Add js from hooks
|
||||||
$parameters=array();
|
$parameters=array();
|
||||||
@ -386,7 +387,8 @@ function LoadProducts(position, issubcat) {
|
|||||||
print $hookmanager->resPrint;
|
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
|
idata++; //Next data everytime
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -414,15 +416,22 @@ function MoreProducts(moreorless) {
|
|||||||
if (pageproducts==0) return; //Return if no less pages
|
if (pageproducts==0) return; //Return if no less pages
|
||||||
pageproducts=pageproducts-1;
|
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);
|
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;
|
pageproducts=pageproducts-1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
idata=<?php echo ($MAXPRODUCT - 2); ?> * pageproducts; //product data counter
|
|
||||||
ishow=0; //product to show counter
|
|
||||||
|
|
||||||
while (ishow < maxproduct) {
|
while (ishow < maxproduct) {
|
||||||
if (typeof (data[idata]) == "undefined") {
|
if (typeof (data[idata]) == "undefined") {
|
||||||
@ -434,10 +443,7 @@ function MoreProducts(moreorless) {
|
|||||||
$("#proprice"+ishow).html("");
|
$("#proprice"+ishow).html("");
|
||||||
$("#proimg"+ishow).attr("src","genimg/empty.png");
|
$("#proimg"+ishow).attr("src","genimg/empty.png");
|
||||||
$("#prodiv"+ishow).data("rowid","");
|
$("#prodiv"+ishow).data("rowid","");
|
||||||
ishow++; //Next product to show after print data product
|
} else {
|
||||||
}
|
|
||||||
else if ((data[idata]['status']) == "1") {
|
|
||||||
//Only show products with status=1 (for sell)
|
|
||||||
$("#prodivdesc"+ishow).show();
|
$("#prodivdesc"+ishow).show();
|
||||||
<?php
|
<?php
|
||||||
if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
|
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']);
|
$("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
|
||||||
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
|
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
|
||||||
$("#prodiv"+ishow).data("iscat",0);
|
$("#prodiv"+ishow).data("iscat",0);
|
||||||
ishow++; //Next product to show after print data product
|
|
||||||
}
|
}
|
||||||
$("#prowatermark"+ishow).hide();
|
$("#prowatermark"+ishow).hide();
|
||||||
|
ishow++; //Next product to show after print data product
|
||||||
idata++; //Next data everytime
|
idata++; //Next data everytime
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user