From d0c298f20b0ab5a6f236caa68bcbccce0192e678 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Tue, 31 Oct 2017 16:04:36 +0100 Subject: [PATCH] caching menu --- modules/privatesales/privatesales.php | 20 ++++++------ .../privatesales_salemenu.php | 32 +++++++++++-------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/modules/privatesales/privatesales.php b/modules/privatesales/privatesales.php index c8a97108..e3c78137 100755 --- a/modules/privatesales/privatesales.php +++ b/modules/privatesales/privatesales.php @@ -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); } } diff --git a/modules/privatesales_salemenu/privatesales_salemenu.php b/modules/privatesales_salemenu/privatesales_salemenu.php index f2a9479d..1024488a 100644 --- a/modules/privatesales_salemenu/privatesales_salemenu.php +++ b/modules/privatesales_salemenu/privatesales_salemenu.php @@ -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,