Merge branch 'ticket-13754-fixSalePosition' into develop

This commit is contained in:
Marion Muszynski 2017-07-20 16:51:38 +02:00
commit 6a88e687c0
5 changed files with 120 additions and 21 deletions

View File

@ -63,7 +63,7 @@ if (isset($_GET['getSales'])){
$export = true;
foreach($sales as $key => $sale) {
$delay = SaleDelay::getDelaySmallName($sale->delivery_delay,2);
echo '<tr id="item_'.$sale->id. '">
echo '<tr id="item_'.$sale->id. '" class="">
<td>'.$sale->id.'</td>
<td>'.$sale->id_category.'</td>
<td><strong>'.$sale->title[intval($cookie->id_lang)].'</strong><br/><span style="color:#666; font-style:italic; font-size:11px;">'.$extrafields[$sale->id][1].'</span></td>
@ -87,11 +87,15 @@ if (isset($_GET['getSales'])){
<td align="center">'.$delay.'</td>
<td align="center">'.(isset($sale_shipping[(int) $sale->id])? ($sale_shipping[(int) $sale->id] == 1? 'Philea': ''): '').'</td>
<td align="center" class="position">';
if($key != 0){
echo '<a href="#" onclick="updatePositionVP(0,'. $sale->position .'); return false;" class="updatePosition" data-way="0" data-position='. $sale->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
}
if($key + 1 != count($sales)){
echo ' <a href="#" class="updatePosition" onclick="updatePositionVP(1,'. $sale->position .'); return false;" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
if($sale->lock_position == 1){
echo '<span class="anticon anticon-lock"></span>';
} else {
if($key != 0){
echo '<a href="#" onclick="updatePositionVP(0,'. $sale->position .'); return false;" class="updatePosition" data-way="0" data-position='. $sale->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
}
if($key + 1 != count($sales)){
echo ' <a href="#" class="updatePosition" onclick="updatePositionVP(1,'. $sale->position .'); return false;" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
}
}
$category_link = Link::getCategoryLink($sale->id_category);
@ -121,6 +125,11 @@ if (isset($_GET['getSales'])){
<i class="glyphicon glyphicon-eye-open"></i> Voir Catégorie BO
</a>
</li>
<li>
<a style="cursor: pointer;" onclick="'.($sale->lock_position?'itemUnLockPosition('.$sale->id.')':'itemLockPosition('.$sale->id.')').'">
<span class="anticon anticon-lock"></span> '.($sale->lock_position?'Défixer':'Fixer').' position
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a style="cursor: pointer;" onclick="itemDeletion('.$sale->id.')">
@ -183,6 +192,10 @@ function updateSalePosition($position, $new_position){
$sale = Sale::getByPosition($position);
$last_sale = Sale::getByPosition($new_position);
if($sale->lock_position || $last_sale->lock_position){
return true;
}
// // update lactuelle new position
Db::getInstance()->autoExecute( _DB_PREFIX_.'privatesale', array(
'position' => $position),
@ -204,25 +217,68 @@ if (isset($_GET['updatePositionDrag'])){
$id_sale = str_replace("item_", "", $_GET['id_sale']);
$position = $_GET['position'];
$sql = 'SELECT position FROM '._DB_PREFIX_.'privatesale WHERE id_sale =' . $id_sale;
$position_initial = Db::getInstance()->getValue($sql);
$sql = 'SELECT position, lock_position FROM '._DB_PREFIX_.'privatesale WHERE id_sale =' . $id_sale;
$query = Db::getInstance()->getRow($sql);
if((int)$query['lock_position']==1){
die();
}
$position_initial = (int)$query['position'];
$new_position = $position_initial + $position;
$sql = 'SELECT lock_position FROM '._DB_PREFIX_.'privatesale WHERE position =' . $new_position;
$is_lock = Db::getInstance()->getValue($sql);
if($is_lock==1){
die();
}
$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 FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". ($position_initial +1) .' AND ' .$new_position;
$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){
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position -1) WHERE id_sale = '. $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 FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". $new_position . ' AND ' . ($position_initial - 1);
} else {
$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){
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position + 1) WHERE id_sale = '. $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 = '.$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();

View File

@ -32,7 +32,7 @@ if(($sponsor = Tools::getValue('sponsor')) && strlen($sponsor) > 12) {
}
if(!class_exists('AntTrackingTag')){
include_once(_PS_MODULE_DIR_.'/ant_trackingtag/models/AntTrackingTag.php');
require_once(_PS_MODULE_DIR_.'/ant_trackingtag/models/AntTrackingTag.php');
}
$tags = AntTrackingTag::getTags();
$url_tag ='';

View File

@ -825,6 +825,7 @@ class AdminPrivateSalesSales extends AdminTab {
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
@ -852,6 +853,7 @@ class AdminPrivateSalesSales extends AdminTab {
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
@ -875,6 +877,7 @@ class AdminPrivateSalesSales extends AdminTab {
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
@ -911,6 +914,7 @@ class AdminPrivateSalesSales extends AdminTab {
$("#saleActive").sortable({
axis : "y",
opacity : 0.6,
cancel: ".not-sortable",
start: function(event, ui) {
initial_position = ui.item.index();
},
@ -927,6 +931,7 @@ class AdminPrivateSalesSales extends AdminTab {
success: function(html) {
var loader = "<p style=\"text-align:center\"><img style=\"display:inline-block;\" src=\"../img/loader_payment.gif\" /></p>";
$(".list_vente").html(loader);
ajax_query();
}
});
@ -1013,11 +1018,15 @@ class AdminPrivateSalesSales extends AdminTab {
<td align="center">'. $sale->forward_news .'</td>
<td align="center" class="position">';
if($key != 0){
echo '<a href="" class="updatePosition" data-way="0" data-position='. $sale->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
}
if($key + 1 != count($sales)){
echo ' <a href="" class="updatePosition" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
if($sale->lock_position == 1){
echo '<span class="anticon anticon-lock"></span>';
} else {
if($key != 0){
echo '<a href="" class="updatePosition" data-way="0" data-position='. $sale->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
}
if($key + 1 != count($sales)){
echo ' <a href="" class="updatePosition" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
}
}
$category_link = Link::getCategoryLink($sale->id_category);
$category_link_bo = '?tab=AdminCatalog&viewcategory&id_category='.$sale->id_category.'&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee));
@ -1046,6 +1055,11 @@ class AdminPrivateSalesSales extends AdminTab {
<i class="glyphicon glyphicon-eye-open"></i> Voir Catégorie BO
</a>
</li>
<li>
<a style="cursor: pointer;" onclick="'.($sale->lock_position?'itemUnLockPosition('.$sale->id.')':'itemLockPosition('.$sale->id.')').'">
<span class="anticon anticon-lock"></span> '.($sale->lock_position?'Défixer':'Fixer').' position
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a style="cursor: pointer;" onclick="itemDeletion('.$sale->id.')">
@ -1270,6 +1284,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'));
}
}
}

View File

@ -15,6 +15,7 @@ class Sale {
var $new = 0;
var $braderie = 0;
var $forward_news = 0;
var $lock_position = 0;
var $id_category;
var $id_employee = 0;
var $shipping_fr = 0;
@ -53,6 +54,7 @@ class Sale {
$this->timelaps = $sale['timelaps'];
$this->sale_type = $sale['sale_type'];
$this->position = $sale['position'];
$this->lock_position = $sale['lock_position'];
$this->delivery_delay = $sale['delivery_delay'];
$this->versions = $sale['versions'];
}
@ -98,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.'
');
@ -112,7 +115,7 @@ class Sale {
// ');
// }
Db::getInstance()->ExecuteS('DELETE FROM `'._DB_PREFIX_.'privatesale_site_version`WHERE `id_sale` = '.(int) $this->id.'');
Db::getInstance()->ExecuteS('DELETE FROM `'._DB_PREFIX_.'privatesale_site_version` WHERE `id_sale` = '.(int) $this->id.'');
foreach($this->versions as $version) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_site_version` VALUES (
@ -195,7 +198,8 @@ class Sale {
NOW(),
'.(int) $this->sale_type.',
'.(int) $this->delivery_delay.',
'.($position+1).'
'.($position+1).',
0
)
');
$this->id = Db::getInstance()->Insert_ID();
@ -281,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);
@ -326,6 +342,7 @@ class Sale {
'braderie' => $ps[0]['braderie'],
'forward_news' => $ps[0]['forward_news'],
'position' => $ps[0]['position'],
'lock_position' => $ps[0]['lock_position'],
'id_category' => $ps[0]['id_category'],
'id_employee' => $ps[0]['id_employee'],
'shipping_fr' => $ps[0]['shipping_fr'],

View File

@ -15,3 +15,9 @@ function ImgDeletion(linkId, ImgId) {
document.location.href = current_location + "&deleteImg=1&image=" + ImgId + "&id=" + linkId;
}
}
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";
}