diff --git a/adm/ajax_vp.php b/adm/ajax_vp.php
index 81da6fea..67aeec60 100644
--- a/adm/ajax_vp.php
+++ b/adm/ajax_vp.php
@@ -125,6 +125,11 @@ if (isset($_GET['getSales'])){
Voir Catégorie BO
+
+
+ '.($sale->lock_position?'Défixer':'Fixer').' position
+
+
@@ -227,76 +232,53 @@ if (isset($_GET['updatePositionDrag'])){
die();
}
- $updated_sales = array();
+ $lock_positions = array();
+ foreach(Db::getInstance()->executeS('SELECT position FROM '._DB_PREFIX_.'privatesale WHERE lock_position = 1') as $lock){
+ $lock_positions[] = (int)$lock['position'];
+ }
+ $_positions = array();
if($position > 0){
- $sales_sql = "SELECT id_sale, position, lock_position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". ($position_initial +1) .' AND ' .$new_position.' ORDER BY position ASC';
+ $sales_sql = "SELECT id_sale, position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". ($position_initial +1) .' AND ' .$new_position.' AND lock_position = 0 ORDER BY position DESC';
$sales = Db::getInstance()->ExecuteS($sales_sql);
foreach ($sales as $key => $sale){
- if(in_array($sale['id_sale'], $updated_sales)){
- continue;
- }
-
- if((int)$sale['lock_position'] == 1){
- $i = 1;
- if(isset($sales[$key+1])){
- $new_sale = $sales[$key+$i];
- $updated_sales[] = (int)$new_sale['id_sale'];
- }
- while ($new_sale) {
- $i++;
- if((int)$new_sale['lock_position'] == 1){
- if(isset($sales[$key+$i])) {
- $new_sale = $sales[$key+$i];
- $updated_sales[] = (int)$new_sale['id_sale'];
- } else {
- $new_sale = false;
- }
- } else {
- Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position -'.$i.') WHERE id_sale = '. $new_sale['id_sale']);
- $new_sale = false;
- }
- }
- } else {
- Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position -1) WHERE id_sale = '. $sale['id_sale']);
- $updated_sales[] = (int)$sale['id_sale'];
+ $pos = (int)$sale['position']-1;
+ while(in_array($pos, $lock_positions)){
+ $pos = $pos - 1;
}
+ $_positions[(int)$sale['id_sale']] = array(
+ 'initial' => (int)$sale['position'],
+ 'new' => $pos,
+ );
+ //Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '.$pos.' WHERE id_sale = '. $sale['id_sale']);
}
} else {
- $sales_sql = "SELECT id_sale, position, lock_position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". $new_position . ' AND ' . ($position_initial - 1).' ORDER BY position ASC';
+ $sales_sql = "SELECT id_sale, position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". $new_position . ' AND ' . ($position_initial - 1).' AND lock_position = 0 ORDER BY position DESC';
$sales = Db::getInstance()->ExecuteS($sales_sql);
foreach ($sales as $key => $sale){
- if(in_array($sale['id_sale'], $updated_sales)){
- continue;
+ $pos = (int)$sale['position']+1;
+ while(in_array($pos, $lock_positions)){
+ $pos = $pos + 1;
}
+ $_positions[(int)$sale['id_sale']] = array(
+ 'initial' => (int)$sale['position'],
+ 'new' => $pos,
+ );
- if((int)$sale['lock_position'] == 1){
- $i = 1;
- if(isset($sales[$key+1])){
- $new_sale = $sales[$key+$i];
- $updated_sales[] = (int)$new_sale['id_sale'];
- }
- while ($new_sale) {
- $i++;
- if((int)$new_sale['lock_position'] == 1){
- if(isset($sales[$key+$i])) {
- $new_sale = $sales[$key+$i];
- $updated_sales[] = (int)$new_sale['id_sale'];
- } else {
- $new_sale = false;
- }
- } else {
- Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position +'.$i.') WHERE id_sale = '. $new_sale['id_sale']);
- $new_sale = false;
- }
- }
- } else {
- Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position + 1) WHERE id_sale = '. $sale['id_sale']);
- $updated_sales[] = (int)$sale['id_sale'];
- }
+ //Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '.$position.' WHERE id_sale = '. $sale['id_sale']);
}
}
+ foreach ($_positions as $id => $value) {
+ Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '. (int)$value['new'].' WHERE id_sale = '. $id);
+ }
+ // die(json_encode(array(
+ // "position" => $position,
+ // "position_initial" => $position_initial,
+ // "new_position" => $new_position,
+ // "sale_positions" => $_positions,
+ // )));
+
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '. (int)$new_position.' WHERE id_sale = '. $id_sale);
die();
diff --git a/modules/privatesales/AdminPrivateSalesSales.php b/modules/privatesales/AdminPrivateSalesSales.php
index cb943ade..51720919 100755
--- a/modules/privatesales/AdminPrivateSalesSales.php
+++ b/modules/privatesales/AdminPrivateSalesSales.php
@@ -930,6 +930,7 @@ class AdminPrivateSalesSales extends AdminTab {
success: function(html) {
var loader = "";
$(".list_vente").html(loader);
+
ajax_query();
}
});
@@ -1055,6 +1056,11 @@ class AdminPrivateSalesSales extends AdminTab {
Voir Catégorie BO
+
+
+ '.($sale->lock_position?'Défixer':'Fixer').' position
+
+
@@ -1273,6 +1279,12 @@ class AdminPrivateSalesSales extends AdminTab {
} elseif(isset($_GET['delete']) && $id_sale = Tools::getValue('id')) {
Sale::deleteSale($id_sale);
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
+ } elseif(isset($_GET['lock_position']) && $id_sale = Tools::getValue('id')) {
+ Sale::lockPosition($id_sale);
+ Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
+ } elseif(isset($_GET['unlock_position']) && $id_sale = Tools::getValue('id')) {
+ Sale::unlockPosition($id_sale);
+ Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
}
}
}
diff --git a/modules/privatesales/Sale.php b/modules/privatesales/Sale.php
index 40b72846..d8f446ec 100755
--- a/modules/privatesales/Sale.php
+++ b/modules/privatesales/Sale.php
@@ -100,6 +100,7 @@ class Sale {
`id_employee` = '.(int) $this->id_employee.',
`shipping_fr` = '.(int) $this->shipping_fr.',
`delivery_delay` = '.(int) $this->delivery_delay.',
+ `lock_position` = '.(int) $this->lock_position.',
`date_upd` = NOW()
WHERE `id_sale` = '.(int) $this->id.'
');
@@ -284,6 +285,18 @@ class Sale {
}
}
+ public static function lockPosition($id) {
+ if($sale = Sale::getSale($id)) {
+ Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET lock_position = 1 WHERE id_sale = '. $id);
+ }
+ }
+
+ public static function unlockPosition($id) {
+ if($sale = Sale::getSale($id)) {
+ Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET lock_position = 0 WHERE id_sale = '. $id);
+ }
+ }
+
public static function rrmdir($dir) {
if(is_dir($dir)) {
$objects = scandir($dir);
diff --git a/modules/privatesales/privatesale.js b/modules/privatesales/privatesale.js
index 3d3a6c75..6cb04f70 100755
--- a/modules/privatesales/privatesale.js
+++ b/modules/privatesales/privatesale.js
@@ -8,3 +8,9 @@ function itemDeletion(linkId) {
document.location.href = current_location + "&id=" + linkId + "&delete=1";
}
}
+function itemLockPosition(linkId) {
+ document.location.href = current_location + "&id=" + linkId + "&lock_position=1";
+}
+function itemUnLockPosition(linkId) {
+ document.location.href = current_location + "&id=" + linkId + "&unlock_position=1";
+}