From bd9ff4fe9eae37aa0c87635eb38cadba9a691230 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Thu, 27 Jul 2017 12:07:35 +0200 Subject: [PATCH] fix position of sale with lock position --- adm/ajax_vp.php | 6 ---- .../privatesales/AdminPrivateSalesSales.php | 13 +++++++ modules/privatesales/Sale.php | 35 ++++++++++++------- modules/privatesales/cron_position.php | 19 ++++++++++ modules/privatesales/privatesale.js | 3 ++ 5 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 modules/privatesales/cron_position.php diff --git a/adm/ajax_vp.php b/adm/ajax_vp.php index 67aeec60..3ad8ae10 100644 --- a/adm/ajax_vp.php +++ b/adm/ajax_vp.php @@ -272,12 +272,6 @@ if (isset($_GET['updatePositionDrag'])){ 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); diff --git a/modules/privatesales/AdminPrivateSalesSales.php b/modules/privatesales/AdminPrivateSalesSales.php index 51720919..5f295e74 100755 --- a/modules/privatesales/AdminPrivateSalesSales.php +++ b/modules/privatesales/AdminPrivateSalesSales.php @@ -955,6 +955,7 @@ class AdminPrivateSalesSales extends AdminTab { +
@@ -1286,5 +1287,17 @@ class AdminPrivateSalesSales extends AdminTab { Sale::unlockPosition($id_sale); Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales')); } + // elseif(isset($_GET['resort_position'])){ + // $nb_sales = Db::getInstance()->getValue(' + // SELECT COUNT(p.`id_sale`) + // FROM `ps_privatesale` p + // WHERE CAST(p.`date_start` AS DATE) = CAST(NOW() AS DATE) + // AND `date_end` > NOW() + // '); + + // if($nb_sales>0) { + // Sale::sortActiveSaleAfterAdd($nb_sales); + // } + // } } } diff --git a/modules/privatesales/Sale.php b/modules/privatesales/Sale.php index c1d45efb..4fbcffdf 100755 --- a/modules/privatesales/Sale.php +++ b/modules/privatesales/Sale.php @@ -268,8 +268,12 @@ class Sale { ) '); } - - self::sortActiveSaleAfterAdd(); + // $today = strtotime(date("Y-m-d H:i:s")); + // $start = strtotime($sale->date_start); + // $end = strtotime($sale->date_end); + // if($start <= $today && $end > $today){ + // self::sortActiveSaleAfterAdd(1); + // } Module::hookExec('privatesales_create', array('sale' => $this)); } @@ -299,18 +303,21 @@ class Sale { } } - public static function sortActiveSaleAfterAdd(){ - foreach(Db::getInstance()->executeS(' - SELECT id_sale, position - FROM '._DB_PREFIX_.'privatesale - WHERE lock_position = 1 - AND `date_end` > NOW() - ORDER BY position DESC - ') as $sale){ - $pos = $sale['position']+1; + public static function sortActiveSaleAfterAdd($nb = 1){ + for ($i=0; $i < $nb; $i++) { + foreach(Db::getInstance()->executeS(' + SELECT id_sale, position + FROM '._DB_PREFIX_.'privatesale + WHERE lock_position = 1 + AND `date_end` > NOW() + AND `date_start` < NOW() + ORDER BY position DESC + ') as $sale){ + $pos = $sale['position']+1; - Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position-1 WHERE position = '. $pos); - Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position+1 WHERE id_sale = '. $sale['id_sale']); + Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position-1 WHERE position = '. $pos); + Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position+1 WHERE id_sale = '. $sale['id_sale']); + } } } @@ -851,6 +858,7 @@ class Sale { if($carrier === "lp") { $carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL'))); + $carriers[] = 22; // dropshipping } else { $carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR'))); } @@ -999,6 +1007,7 @@ class Sale { if($carrier === "lp") { $carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL'))); + $carriers[] = 22; // dropshipping } else { $carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR'))); } diff --git a/modules/privatesales/cron_position.php b/modules/privatesales/cron_position.php new file mode 100644 index 00000000..7505b9ea --- /dev/null +++ b/modules/privatesales/cron_position.php @@ -0,0 +1,19 @@ +getValue(' + SELECT COUNT(p.`id_sale`) + FROM `ps_privatesale` p + WHERE CAST(p.`date_start` AS DATE) = CAST(NOW() AS DATE) + AND `date_end` > NOW() +'); + +if($nb_sales>0) { + Sale::sortActiveSaleAfterAdd($nb_sales); +} \ No newline at end of file diff --git a/modules/privatesales/privatesale.js b/modules/privatesales/privatesale.js index 6cb04f70..7b6599b5 100755 --- a/modules/privatesales/privatesale.js +++ b/modules/privatesales/privatesale.js @@ -14,3 +14,6 @@ function itemLockPosition(linkId) { function itemUnLockPosition(linkId) { document.location.href = current_location + "&id=" + linkId + "&unlock_position=1"; } +function resortPosition() { + document.location.href = current_location + "&resort_position=1"; +}