diff --git a/adm/ajax_vp.php b/adm/ajax_vp.php index 351b245e..5c55c2ee 100644 --- a/adm/ajax_vp.php +++ b/adm/ajax_vp.php @@ -9,14 +9,20 @@ require_once('../modules/privatesales/Sale.php'); require_once('../modules/privatesales_delay/saledelay.php'); require_once('../modules/privatesales_extrafields/privatesales_extrafields.php'); +if (isset($_GET['flush_sale'])){ + $replies = CacheRedis::getInstance()->clear('sale*'); + echo '
';var_dump($replies);echo '
';die(); + //echo 'Clear cache'; + die(); +} if (isset($_GET['getSales'])){ global $cookie; $type = $_GET['type']; 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{ - $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(); diff --git a/adm/helpers/HelperFormBootstrap.php b/adm/helpers/HelperFormBootstrap.php index c5e93bdd..c8f4802b 100644 --- a/adm/helpers/HelperFormBootstrap.php +++ b/adm/helpers/HelperFormBootstrap.php @@ -672,7 +672,7 @@ class HelperFormBootstrap{ public function inputTextL($p = array()){ $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 .= '
@@ -1062,7 +1080,7 @@ class AdminPrivateSalesSales extends AdminTab { '; echo ' '; - $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(); foreach ($sales as $key => $sale) { $ids[] = $sale->id; @@ -1109,7 +1127,8 @@ class AdminPrivateSalesSales extends AdminTab { echo ' Bas'; } } - $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)); echo ' diff --git a/modules/privatesales/Sale.php b/modules/privatesales/Sale.php index f98f046a..a3661ad9 100755 --- a/modules/privatesales/Sale.php +++ b/modules/privatesales/Sale.php @@ -1646,7 +1646,93 @@ class Sale { $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); CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $sales); } else { diff --git a/modules/privatesales_extrafields/privatesales_extrafields.php b/modules/privatesales_extrafields/privatesales_extrafields.php index f0ee3a17..e2bf1ce1 100755 --- a/modules/privatesales_extrafields/privatesales_extrafields.php +++ b/modules/privatesales_extrafields/privatesales_extrafields.php @@ -230,9 +230,9 @@ class PrivateSales_ExtraFields extends Module { foreach($this->_languages as $language) { echo '
'; if($field['type'] == 1) { - echo ''; + echo ''; } else { - echo ''; + echo ''; } echo '
';