test flush cache sale

This commit is contained in:
Marion Muszynski 2017-10-30 13:41:50 +01:00
parent 6f3b5615dc
commit 07dd8ab9c9
5 changed files with 121 additions and 10 deletions

View File

@ -9,14 +9,20 @@ require_once('../modules/privatesales/Sale.php');
require_once('../modules/privatesales_delay/saledelay.php'); require_once('../modules/privatesales_delay/saledelay.php');
require_once('../modules/privatesales_extrafields/privatesales_extrafields.php'); require_once('../modules/privatesales_extrafields/privatesales_extrafields.php');
if (isset($_GET['flush_sale'])){
$replies = CacheRedis::getInstance()->clear('sale*');
echo '<pre>';var_dump($replies);echo '</pre>';die();
//echo 'Clear cache';
die();
}
if (isset($_GET['getSales'])){ if (isset($_GET['getSales'])){
global $cookie; global $cookie;
$type = $_GET['type']; $type = $_GET['type'];
if($type == 'finished'){ if($type == 'finished'){
$sales = Sale::getSales(NULL, NULL, NULL, FALSE , FALSE, FALSE, '`position` DESC', NULL, NULL, FALSE, FALSE); $sales = Sale::getSalesBack(NULL, NULL, NULL, FALSE , FALSE, FALSE, '`position` DESC', NULL, NULL, FALSE, FALSE);
}else{ }else{
$sales = Sale::getSales(NULL, NULL, NULL, $type , FALSE, FALSE, '`position` DESC', NULL, NULL, FALSE, FALSE); $sales = Sale::getSalesBack(NULL, NULL, NULL, $type , FALSE, FALSE, '`position` DESC', NULL, NULL, FALSE, FALSE);
} }
$ids = array(); $ids = array();

View File

@ -672,7 +672,7 @@ class HelperFormBootstrap{
public function inputTextL($p = array()){ public function inputTextL($p = array()){
$default_value = (isset($p['default']) ? $p['default'] : ''); $default_value = (isset($p['default']) ? $p['default'] : '');
$defaultLanguage = $p['default_language'] ? $p['default_language'] : 2; $defaultLanguage = isset($p['default_language']) ? $p['default_language'] : 2;
$this->_html .= ' $this->_html .= '
<div class="form-group"> <div class="form-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'"> <label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">
@ -702,7 +702,7 @@ class HelperFormBootstrap{
public function inputTextareaL($p = array()){ public function inputTextareaL($p = array()){
$default_value = (isset($p['default']) ? $p['default'] : ''); $default_value = (isset($p['default']) ? $p['default'] : '');
$defaultLanguage = $p['default_language'] ? $p['default_language'] : 2; $defaultLanguage = isset($p['default_language']) ? $p['default_language'] : 2;
$this->_html .= ' $this->_html .= '
<div class="form-group"> <div class="form-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'"> <label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">

View File

@ -169,7 +169,7 @@ class AdminPrivateSalesSales extends AdminTab {
$helperForm->_forms = array( $helperForm->_forms = array(
array( array(
'action' => $base_link, 'action' => $currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'),
'title' => $this->l('Création Catégorie principale'), 'title' => $this->l('Création Catégorie principale'),
'icon' => '<span class="glyphicon glyphicon-list"></span> ', 'icon' => '<span class="glyphicon glyphicon-list"></span> ',
'class' => 'form-horizontal', 'class' => 'form-horizontal',
@ -936,6 +936,23 @@ class AdminPrivateSalesSales extends AdminTab {
} }
}); });
$(".flush[name='flush']").click(function(){
if(!$(this).hasClass('active')){
var loader = "<img width='20px' src='../img/loader_2.gif' />";
$(this).html(loader);
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'flush_sale',
success: function(html) {
console.log(html);
$(".flush[name='flush']").html('Clear cache');
$(".flush[name='flush']").blur();
}
});
}
});
$(".updatePosition").click(function(e) { $(".updatePosition").click(function(e) {
e.preventDefault(); e.preventDefault();
var position = $(this).attr('data-position'); var position = $(this).attr('data-position');
@ -1034,6 +1051,7 @@ class AdminPrivateSalesSales extends AdminTab {
<button type="submit" name="not_ended" class="tri btn btn-default active">Ventes actuelles</button> <button type="submit" name="not_ended" class="tri btn btn-default active">Ventes actuelles</button>
<button type="submit" name="finished" class="tri btn btn-default">Ventes terminées</button> <button type="submit" name="finished" class="tri btn btn-default">Ventes terminées</button>
<button type="submit" name="all" class="tri btn btn-default">Toutes les ventes</button> <button type="submit" name="all" class="tri btn btn-default">Toutes les ventes</button>
<button type="submit" name="flush" class="flush btn btn-default">Clear cache</button>
<!--a style="cursor: pointer;" onclick="resortPosition();" class="btn btn-default">Resort</a--> <!--a style="cursor: pointer;" onclick="resortPosition();" class="btn btn-default">Resort</a-->
</div> </div>
</div> </div>
@ -1062,7 +1080,7 @@ class AdminPrivateSalesSales extends AdminTab {
</thead>'; </thead>';
echo ' <tbody id="saleActive" class="sortable">'; echo ' <tbody id="saleActive" class="sortable">';
$sales = Sale::getSales(NULL, NULL, NULL, 'not_ended', FALSE, FALSE, '`position` DESC'); $sales = Sale::getSalesBack(NULL, NULL, NULL, 'not_ended', FALSE, FALSE, '`position` DESC');
$ids = array(); $ids = array();
foreach ($sales as $key => $sale) { foreach ($sales as $key => $sale) {
$ids[] = $sale->id; $ids[] = $sale->id;
@ -1109,7 +1127,8 @@ class AdminPrivateSalesSales extends AdminTab {
echo ' <a href="" class="updatePosition" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>'; 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); $link = new Link();
$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)); $category_link_bo = '?tab=AdminCatalog&viewcategory&id_category='.$sale->id_category.'&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee));
echo '</td> echo '</td>
<td> <td>

View File

@ -1646,7 +1646,93 @@ class Sale {
$query .= ' LIMIT '.$limit; $query .= ' LIMIT '.$limit;
} }
if ($future == 'current' && false === ($sales = CacheRedis::getInstance()->getQuery($query, self::CONTROLLER_NAME))) { if (false === ($sales = CacheRedis::getInstance()->getQuery($query, self::CONTROLLER_NAME))) {
$sales = Db::getInstance()->ExecuteS($query);
CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $sales);
}
if($sales) {
if($lite) {
foreach($sales AS $sale) {
$result[] = $sale['id_sale'];
}
} else {
foreach($sales AS $sale) {
$result[] = new Sale($sale['id_sale']);
}
}
}
return $result;
}
public static function getSalesBack($enabled=NULL, $logout=NULL, $featured=NULL, $future=NULL, $lite=FALSE, $pub=FALSE, $order_by='`date_end` ASC', $limit=NULL, $sale_type=NULL, $site_version=FALSE, $without_consumable=FALSE) {
global $cookie;
$result = array();
$where = array();
$query = '
SELECT p.`id_sale`
FROM `'._DB_PREFIX_.'privatesale` p
';
// if($sale_type !== NULL){
// $query.= ' LEFT JOIN `'._DB_PREFIX_.'privatesale_type` pt ON(pt.id_sale = p.id_sale AND pt.id_sale_type = '. $sale_type.')';
// }
if($site_version !== FALSE) {
$query .= '
LEFT JOIN `'._DB_PREFIX_.'privatesale_site_version` sv
ON p.`id_sale` = sv.`id_sale`
';
$where[] = 'sv.`version` = "'.pSQL($site_version).'"';
}
if($enabled !== NULL OR $logout !== NULL OR $featured !== NULL OR $future !== NULL) {
$enabled !== null? $where[] = '`enabled` = '.(int) $enabled: TRUE;
$logout !== null? $where[] = '`logout` = '.(int) $logout: TRUE;
$pub != FALSE? '': $where[] = '`public` = 0';
$featured !== null? $where[] = '`featured` = '.(int) $featured: TRUE;
// $sale_type !== NULL? $where[] = '`sale_type` = '.(int) $sale_type: TRUE;
if($future === 'current') {
$where[] = '`date_start` < NOW() AND `date_end` > NOW()';
} elseif($future === 'not_ended') {
$where[] = '`date_end` > NOW()';}
elseif($future === 'all') {
$where[] = ' 1 = 1';
} elseif ($future === 'today') {
$where[] = 'CAST(`date_start` AS DATE) = CAST(NOW() AS DATE)';
} elseif ($future === 'tomorrow') {
$where[] = 'CAST(`date_start` AS DATE) = CAST(DATE_ADD(NOW(), INTERVAL 1 DAY) AS DATE)';
} elseif ($future === 'last') {
$where[] = 'CAST(`date_end` AS DATE) = CAST(NOW() AS DATE)';
} elseif ($future === 'ended_tomorrow') {
$where[] = 'CAST(`date_end` AS DATE) = CAST(DATE_ADD(NOW(), INTERVAL 1 DAY) AS DATE)';
} elseif(is_int($future)) {
$where[] = '(`date_start` > NOW() AND `date_start` < DATE_ADD(NOW(), INTERVAL '.$future.' DAY))';
} elseif($future === TRUE) {
$where[] = '`date_start` > NOW()';
} elseif($future === FALSE) {
$where[] = '`date_start` < NOW() AND `date_end` < NOW()';
}
$query .= 'WHERE '.implode(' AND ', $where);
}
// if($sale_type !== NULL){
// $query.= ' AND pt.id_sale_type = '. $sale_type;
// }
if ($without_consumable && _SHOP_CATEGORYENABLED!== FALSE) {
$query .= ' AND p.`id_sale` != '.(int) _SHOP_PRIVATESALES_CONSUMABLE;
}
$query .= ' ORDER BY '.$order_by;
if($limit !== NULL) {
$query .= ' LIMIT '.$limit;
}
if ($future == FALSE && false === ($sales = CacheRedis::getInstance()->getQuery($query, self::CONTROLLER_NAME))) {
$sales = Db::getInstance()->ExecuteS($query); $sales = Db::getInstance()->ExecuteS($query);
CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $sales); CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $sales);
} else { } else {

View File

@ -230,9 +230,9 @@ class PrivateSales_ExtraFields extends Module {
foreach($this->_languages as $language) { foreach($this->_languages as $language) {
echo '<div id="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">'; echo '<div id="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">';
if($field['type'] == 1) { if($field['type'] == 1) {
echo '<textarea class="form-control" name="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'">'.Tools::safeOutput($fields_values[$field['id_field']][$language['id_lang']], TRUE).'</textarea>'; echo '<textarea class="form-control" name="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'">'.(isset($fields_values[$field['id_field']][$language['id_lang']])?Tools::safeOutput($fields_values[$field['id_field']][$language['id_lang']], TRUE):'').'</textarea>';
} else { } else {
echo '<input type="text" class="form-control" name="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'" value="'.Tools::safeOutput($fields_values[$field['id_field']][$language['id_lang']], TRUE).'" />'; echo '<input type="text" class="form-control" name="m_extrafields_'.$field['id_field'].'_value_'.$language['id_lang'].'" value="'.(isset($fields_values[$field['id_field']][$language['id_lang']])?Tools::safeOutput($fields_values[$field['id_field']][$language['id_lang']], TRUE):'').'" />';
} }
echo ' echo '
</div>'; </div>';