fix bug updateposition on big product list

This commit is contained in:
Marion Muszynski 2016-09-23 16:59:49 +02:00
parent 16ba72aa98
commit 4d2f0e1f9a
2 changed files with 68 additions and 17 deletions

View File

@ -246,6 +246,47 @@ class AdminProducts extends AdminTab
Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token));
}
if (Tools::isSubmit('clean_positionproduct')) {
global $cookie, $currentIndex;
if ($cookie->id_employee == 1) {
$category_products = Db::getInstance()->ExecuteS('
SELECT cp.`id_product`, cp.`position`, cp.`id_category`
FROM `'._DB_PREFIX_.'category_product` cp
WHERE cp.`id_category` = '.(int)$this->_category->id.'
ORDER BY cp.`position` ASC
');
// Position mise à 0
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category_product`
SET `position` = 0
WHERE `id_category` = '.(int)$this->_category->id
);
$pos = 0;
foreach ($category_products as $key => $cat_product) {
if(Validate::isLoadedObject($product = new Product((int)$cat_product['id_product']))){
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category_product`
SET `position` = '. (int)($pos) .'
WHERE `id_product` = '.(int)$cat_product['id_product'].'
AND `id_category`='.(int)$this->_category->id
);
$pos++;
} else {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` = '.(int)$this->_category->id.'
AND `id_product` = '.(int)$cat_product['id_product'].'
');
continue;
}
}
}
Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token));
}
if (Tools::isSubmit('reorderproduct') || Tools::isSubmit('reordersubproduct')) {
global $cookie, $currentIndex;
@ -1938,6 +1979,10 @@ class AdminProducts extends AdminTab
echo '<p><input type="submit" class="button" name="reordersub'.$this->table.'" value="'.$this->l('Order products').'" /></p>';
echo '<p>'.$this->l('Order by product name').'</p>';
}
if((int)$this->_category->id_oarent !=1 && $cookie->id_employee==1){
echo '<p><input type="submit" class="button" name="clean_position'.$this->table.'" value="'.$this->l('Order products').'" /></p>';
echo '<p>'.$this->l('Re-Order by product position, clean all position of the category').'</p>';
}
echo '</form>';
if (isset($this->_includeTab) AND sizeof($this->_includeTab))

View File

@ -1,5 +1,5 @@
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@ -26,7 +26,7 @@
$(document).ready(function() {
$('table.tableDnD').tableDnD({
onDragStart: function(table, row) {
originalOrder = $.tableDnD.serialize();
reOrder = ':even';
@ -38,7 +38,7 @@ $(document).ready(function() {
onDragClass: 'myDragClass',
onDrop: function(table, row) {
if (originalOrder != $.tableDnD.serialize()) {
var url_params = $.tableDnD.serialize();
var way = (originalOrder.indexOf(row.id) < $.tableDnD.serialize().indexOf(row.id))? 1 : 0;
var ids = row.id.split('_');
var tableDrag = $('#' + table.id);
@ -76,19 +76,25 @@ $(document).ready(function() {
token: token
};
if (table.id == 'product') {
// @Override Antadis - Passing product array in Post to prevent bug when too many products on list (url request too long)
var post_params = url_params.replace(/&/g,"");
post_params = post_params.split("product[]=");
post_params.splice(0, 1);;
params = {
ajaxProductsPositions: true,
id_category: ids[1],
id_product: ids[2],
way: way,
token: token
token: token,
product : post_params
};
url_params = '';
}
$.ajax({
type: 'POST',
async: false,
url: 'ajax.php?' + $.tableDnD.serialize(),
url: 'ajax.php?'+url_params,
data: params,
success: function(data) {
if (come_from == 'AdminModulesPositions') {
@ -105,21 +111,21 @@ $(document).ready(function() {
var reg = /_[0-9][0-9]*$/g;
tableDrag.find('tbody tr').each(function(i) {
$(this).attr('id', $(this).attr('id').replace(reg, '_' + i));
// Update link position
var up_reg = new RegExp('position=[-]?[0-9]+&');
// Up links
$(this).find('td.dragHandle a:odd').attr('href', $(this).find('td.dragHandle a:odd').attr('href').replace(up_reg, 'position='+ (i - 1) +'&'));
// Down links
$(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&'));
});
tableDrag.find('tr').not('.nodrag').removeClass('alt_row');
tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row');
tableDrag.find('tr td.dragHandle a:hidden').show();
if (alternate) {
tableDrag.find('tr td.dragHandle:first a:odd').hide();
tableDrag.find('tr td.dragHandle:last a:even').hide();
@ -129,27 +135,27 @@ $(document).ready(function() {
tableDrag.find('tr td.dragHandle:last a:odd').hide();
}
}
else
else
{
var reg = /_[0-9]$/g;
tableDrag.find('tbody tr').each(function(i) {
$(this).attr('id', $(this).attr('id').replace(reg, '_' + i));
// Update link position
var up_reg = new RegExp('position=[-]?[0-9]+&');
// Up links
$(this).find('td.dragHandle a:odd').attr('href', $(this).find('td.dragHandle a:odd').attr('href').replace(up_reg, 'position='+ (i - 1) +'&'));
// Down links
$(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&'));
});
tableDrag.find('tr').not('.nodrag').removeClass('alt_row');
tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row');
tableDrag.find('tr td.dragHandle a:hidden').show();
if (alternate) {
tableDrag.find('tr td.dragHandle:first a:odd').hide();
tableDrag.find('tr td.dragHandle:last a:even').hide();