caching menu

This commit is contained in:
Marion Muszynski 2017-10-31 16:04:36 +01:00
parent b443abd67c
commit d0c298f20b
2 changed files with 29 additions and 23 deletions

View File

@ -406,11 +406,11 @@ class PrivateSales extends Module {
$display_limit = Configuration::get('PRIVATESALES_FUTURELIMIT');
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $site_version_front,TRUE);
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $site_version_front, TRUE);
if($display_limit == 0) {
$futuresales = Sale::getSales(TRUE, NULL, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` ASC', NULL, NULL, $site_version_front,TRUE);
$futuresales = Sale::getSales(TRUE, NULL, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` ASC', NULL, NULL, $site_version_front, TRUE);
} else {
$futuresales = Sale::getSales(TRUE, NULL, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` ASC', NULL, NULL, $site_version_front,TRUE);
$futuresales = Sale::getSales(TRUE, NULL, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` ASC', NULL, NULL, $site_version_front, TRUE);
}
$smarty->assign(array(
@ -439,23 +439,23 @@ class PrivateSales extends Module {
}
public function hookFooter($params) {
global $smarty, $cookie;
global $smarty, $cookie, $site_version_front;
$display_limit = Configuration::get('PRIVATESALES_FUTURELIMIT');
if($cookie->isLogged()) {
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
if($display_limit == 0) {
$futuresales = Sale::getSales(TRUE, NULL, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$futuresales = Sale::getSales(TRUE, NULL, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
} else {
$futuresales = Sale::getSales(TRUE, NULL, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$futuresales = Sale::getSales(TRUE, NULL, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
}
} else {
$sales = Sale::getSales(TRUE, TRUE, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$sales = Sale::getSales(TRUE, TRUE, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
if($display_limit == 0) {
$futuresales = Sale::getSales(TRUE, TRUE, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$futuresales = Sale::getSales(TRUE, TRUE, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
} else {
$futuresales = Sale::getSales(TRUE, TRUE, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, FALSE, TRUE);
$futuresales = Sale::getSales(TRUE, TRUE, NULL, (int) $display_limit, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'),'`date_end` ASC', NULL, NULL, $site_version_front, TRUE);
}
}

View File

@ -18,29 +18,30 @@ class PrivateSales_SaleMenu extends Module {
return parent::install() && $this->registerHook('top');
}
public function hookSubTop($params) {
return $this->hookTop($params);
}
public function hookTop($params) {
global $cookie, $smarty;
global $cookie, $smarty, $site_version_front;
include_once dirname(__FILE__).'/../privatesales/Sale.php';
if(_PS_MOBILE_)
return false;
/*
if($cookie->isLogged()) {
*/
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`date_start` ASC');
//$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`date_start` ASC');
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $site_version_front, TRUE);
$sales_1 = array();
$sales_2 = array();
$sales_3 = array();
$sale_ids = array();
foreach($sales as $sale) {
if($sale->sale_type !== NULL) {
if($sale->sale_type == 1) {
@ -53,18 +54,23 @@ class PrivateSales_SaleMenu extends Module {
}
$sale_ids[] = (int) $sale->id;
}
$extra_sale_fields = array();
foreach(Db::getInstance()->ExecuteS('
$query = '
SELECT `id_sale`, `value`
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
WHERE `id_sale` IN ('.implode(', ', $sale_ids).')
AND `id_lang` = '.(int) $cookie->id_lang.'
AND `id_field` = 1
') as $row) {
$extra_sale_fields[(int) $row['id_sale']] = $row['value'];
}
';
if (false === ($extra_sale_fields = CacheRedis::getInstance()->getQuery($query, 'sale'))) {
$extra_sale_fields = array();
foreach(Db::getInstance()->ExecuteS($query) as $row) {
$extra_sale_fields[(int) $row['id_sale']] = $row['value'];
}
CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $extra_sale_fields);
}
$smarty->assign(array(
'menu_sales' => $sales,
'menu_sales_1' => $sales_1,