diff --git a/adm/tabs/AdminProducts.php b/adm/tabs/AdminProducts.php index 27fcb2d3..52660722 100755 --- a/adm/tabs/AdminProducts.php +++ b/adm/tabs/AdminProducts.php @@ -245,6 +245,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; @@ -1939,6 +1980,10 @@ class AdminProducts extends AdminTab echo '
'; echo ''.$this->l('Order by product name').'
'; } + if((int)$this->_category->id_oarent !=1 && $cookie->id_employee==1){ + echo ''; + echo ''.$this->l('Re-Order by product position, clean all position of the category').'
'; + } echo ''; if (isset($this->_includeTab) AND sizeof($this->_includeTab)) @@ -4497,6 +4542,12 @@ class AdminProducts extends AdminTab } public function getFieldValue($obj, $data, $id_lang) { + global $cookie; + + // if ($id_lang == 0) { + // $id_lang = (int)($cookie->id_lang); + // } + $customs_data = Db::getInstance()->getRow(' SELECT `nc8`, `id_country` FROM `'._DB_PREFIX_.'product_customs` diff --git a/js/admin-dnd.js b/js/admin-dnd.js index 476413ce..c7acdaa7 100755 --- a/js/admin-dnd.js +++ b/js/admin-dnd.js @@ -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(); diff --git a/modules/braderie/AdminBraderie.php b/modules/braderie/AdminBraderie.php index 7fad37ce..229ada66 100644 --- a/modules/braderie/AdminBraderie.php +++ b/modules/braderie/AdminBraderie.php @@ -212,6 +212,10 @@ class AdminBraderie extends AdminTab return false; }); + // $("#formBraderie").submit(function(){ + // return false; + // }); + $("#add_button").click(function(event) { event.preventDefault(); return false; @@ -374,7 +378,7 @@ class AdminBraderie extends AdminTab - + '.$this->l('Voir cette catégorie').' diff --git a/modules/braderie/ajax.php b/modules/braderie/ajax.php index 0766a603..58d24ef7 100644 --- a/modules/braderie/ajax.php +++ b/modules/braderie/ajax.php @@ -282,7 +282,7 @@ function addToSellout() Image::duplicateProductImages($id_product_old, $product->id, $combinationImages); } - return Tools::displayError('Le produit ajoute dans la braderie'); + return Tools::displayError('Le produit a été ajouté à la braderie'); } function pSQLArray($data)