diff --git a/classes/Customer.php b/classes/Customer.php index f84177853..55429fcb3 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -598,9 +598,12 @@ class CustomerCore extends ObjectModel public static function getGroupsStatic($id_customer) { - if (!Group::isFeatureActive() || $id_customer == 0) + if (!Group::isFeatureActive()) return array(Configuration::get('PS_CUSTOMER_GROUP')); + if ($id_customer == 0) + self::$_customer_groups[$id_customer] = array((int)Configuration::get('PS_UNIDENTIFIED_GROUP')); + if (!isset(self::$_customer_groups[$id_customer])) { self::$_customer_groups[$id_customer] = array(); diff --git a/classes/Tools.php b/classes/Tools.php index 8d32f2a35..f49b44acb 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -1830,6 +1830,7 @@ exit; self::$_caching = (int)$smarty->caching; $smarty->force_compile = 0; $smarty->caching = (int)$level; + $smarty->cache_lifetime = 31536000; // 1 Year } public static function restoreCacheSettings(Context $context = null) diff --git a/classes/module/Module.php b/classes/module/Module.php index 901a7e370..ccde9b6cd 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1582,11 +1582,18 @@ abstract class ModuleCore { return Module::_isTemplateOverloadedStatic($this->name, $template); } + + protected function getCacheId($name = null) + { + if ($name === null) + $name = $this->name; + return $name.'|'.(int)$this->context->shop->id.'_'.(int)Group::getCurrent()->id.'_'.(int)$this->context->language->id; + } public function display($file, $template, $cacheId = null, $compileId = null) { if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null) - $result = Tools::displayError('No template found for module').' '.basename($file, '.php'); + return Tools::displayError('No template found for module').' '.basename($file, '.php'); else { $this->smarty->assign(array( @@ -1594,16 +1601,22 @@ abstract class ModuleCore 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/' )); + if ($cacheId !== null) + Tools::enableCache(); + $smarty_subtemplate = $this->context->smarty->createTemplate( $this->getTemplatePath($template), $cacheId, $compileId, $this->smarty ); - $result = $smarty_subtemplate->fetch(); + + if ($cacheId !== null) + Tools::restoreCacheSettings(); + + return $result; } - return $result; } /** @@ -1635,7 +1648,11 @@ abstract class ModuleCore { $context = Context::getContext(); - return $context->smarty->isCached($this->getTemplatePath($template), $cacheId, $compileId); + Tools::enableCache(); + $is_cached = $context->smarty->isCached($this->getTemplatePath($template), $cacheId, $compileId); + Tools::restoreCacheSettings(); + + return $is_cached; } protected function _clearCache($template, $cache_id = null, $compile_id = null) diff --git a/modules/blockadvertising/blockadvertising.php b/modules/blockadvertising/blockadvertising.php index 09afa9888..4c762b1ab 100644 --- a/modules/blockadvertising/blockadvertising.php +++ b/modules/blockadvertising/blockadvertising.php @@ -157,6 +157,7 @@ class BlockAdvertising extends Module // Reset the module properties $this->initialize(); + $this->_clearCache('blockadvertising.tpl'); } if ($errors) echo $this->displayError($errors); @@ -216,13 +217,14 @@ class BlockAdvertising extends Module public function hookRightColumn($params) { - $this->smarty->assign(array( - 'image' => $this->context->link->protocol_content.$this->adv_img, - 'adv_link' => $this->adv_link, - 'adv_title' => $this->adv_title, - )); + if (!$this->isCached('blockadvertising.tpl', $this->getCacheId())) + $this->smarty->assign(array( + 'image' => $this->context->link->protocol_content.$this->adv_img, + 'adv_link' => $this->adv_link, + 'adv_title' => $this->adv_title, + )); - return $this->display(__FILE__, 'blockadvertising.tpl'); + return $this->display(__FILE__, 'blockadvertising.tpl', $this->getCacheId()); } public function hookLeftColumn($params) diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index 091833f4c..828efe73e 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -156,31 +156,23 @@ class BlockCategories extends Module } public function hookLeftColumn($params) - { - $id_customer = (int)$params['cookie']->id_customer; - // Get all groups for this customer and concatenate them as a string: "1,2,3..." - // It is necessary to keep the group query separate from the main select query because it is used for the cache - $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : Configuration::get('PS_UNIDENTIFIED_GROUP'); - $id_product = (int)Tools::getValue('id_product', 0); - $id_category = (int)Tools::getValue('id_category', 0); - $id_lang = (int)$params['cookie']->id_lang; - $smartyCacheId = 'blockcategories|'.$this->context->shop->id.'_'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category; - $this->context->smarty->cache_lifetime = 31536000; // 1 Year - Tools::enableCache(); - if (!$this->isCached('blockcategories.tpl', $smartyCacheId)) + { + if (!$this->isCached('blockcategories.tpl', $this->getCacheId())) { + // Get all groups for this customer and concatenate them as a string: "1,2,3..." + $groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id)); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c - INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.Shop::addSqlRestrictionOnLang('cl').') + INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').') INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.') WHERE (c.`active` = 1 OR c.`id_category` = '.(int)Configuration::get('PS_HOME_CATEGORY').') AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').' '.((int)$maxdepth != 0 ? ' AND `level_depth` <= '.(int)$maxdepth : '').' AND c.id_category IN (SELECT id_category FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` IN ('.pSQL($groups).')) ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'))) - return Tools::restoreCacheSettings(); + return; $resultParents = array(); $resultIds = array(); @@ -203,7 +195,7 @@ class BlockCategories extends Module if (Tools::isSubmit('id_product')) { if (!isset($this->context->cookie->last_visited_category) - || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category))) + || !Product::idIsOnCategoryId((int)Tools::getValue('id_product'), array('0' => array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) { $product = new Product($id_product); @@ -220,31 +212,33 @@ class BlockCategories extends Module $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); $this->smarty->assign('isDhtml', $isDhtml); } - $display = $this->display(__FILE__, 'blockcategories.tpl', $smartyCacheId); - Tools::restoreCacheSettings(); + $display = $this->display(__FILE__, 'blockcategories.tpl', $this->getCacheId()); return $display; } + protected function getCacheId($name = null) + { + parent::getCacheId($name); + + $groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id)); + $id_product = (int)Tools::getValue('id_product', 0); + $id_category = (int)Tools::getValue('id_category', 0); + $id_lang = (int)$this->context->language->id; + return 'blockcategories|'.$this->context->shop->id.'_'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category; + } + public function hookFooter($params) { - $id_customer = (int)($params['cookie']->id_customer); // Get all groups for this customer and concatenate them as a string: "1,2,3..." - $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_; - $id_product = (int)(Tools::getValue('id_product', 0)); - $id_category = (int)(Tools::getValue('id_category', 0)); - $id_lang = (int)($params['cookie']->id_lang); - $smartyCacheId = 'blockcategories|'.$this->context->shop->id.'_'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category; - $this->context->smarty->cache_lifetime = 31536000; // 1 Year - Tools::enableCache(); - if (!$this->isCached('blockcategories_footer.tpl', $smartyCacheId)) + if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId())) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); - + $groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id)); if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c '.Shop::addSqlAssociation('category', 'c').' - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.Shop::addSqlRestrictionOnLang('cl').') + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE (c.`active` = 1 OR c.`id_category` = 1) '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' @@ -296,8 +290,8 @@ class BlockCategories extends Module $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); $this->smarty->assign('isDhtml', $isDhtml); } - $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId); - Tools::restoreCacheSettings(); + $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $this->getCacheId()); + return $display; } diff --git a/modules/blockcontact/blockcontact.php b/modules/blockcontact/blockcontact.php index 6192e6c83..bdddb9ce6 100644 --- a/modules/blockcontact/blockcontact.php +++ b/modules/blockcontact/blockcontact.php @@ -19,7 +19,7 @@ * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA -* @copyright 2007-2013 PrestaShop SA +* @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @@ -64,6 +64,7 @@ class Blockcontact extends Module { Configuration::updateValue('blockcontact_telnumber', Tools::getValue('telnumber')); Configuration::updateValue('blockcontact_email', Tools::getValue('email')); + $this->_clearCache('blockcontact.tpl'); $html .= '
'.$this->l('Configuration updated').'
'; } @@ -94,12 +95,12 @@ class Blockcontact extends Module public function hookDisplayRightColumn() { global $smarty; - - $smarty->assign(array( - 'telnumber' => Configuration::get('blockcontact_telnumber'), - 'email' => Configuration::get('blockcontact_email') - )); - return $this->display(__FILE__, 'blockcontact.tpl'); + if (!$this->isCached('blockcontact.tpl', $this->getCacheId())) + $smarty->assign(array( + 'telnumber' => Configuration::get('blockcontact_telnumber'), + 'email' => Configuration::get('blockcontact_email') + )); + return $this->display(__FILE__, 'blockcontact.tpl', $this->getCacheId()); } public function hookDisplayLeftColumn() diff --git a/modules/blockcontactinfos/blockcontactinfos.php b/modules/blockcontactinfos/blockcontactinfos.php index fa3ea0338..ebc8ca2a9 100644 --- a/modules/blockcontactinfos/blockcontactinfos.php +++ b/modules/blockcontactinfos/blockcontactinfos.php @@ -19,7 +19,8 @@ * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA -* @copyright 2007-2013 PrestaShop SA +* @copyright 2007-2013 PrestaShop SA + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @@ -71,7 +72,7 @@ class Blockcontactinfos extends Module Configuration::updateValue('blockcontactinfos_address', ((isset($_POST['address']) && $_POST['address'] != '') ? $_POST['address'] : '')); Configuration::updateValue('blockcontactinfos_phone', ((isset($_POST['phone']) && $_POST['phone'] != '') ? $_POST['phone'] : '')); Configuration::updateValue('blockcontactinfos_email', ((isset($_POST['email']) && $_POST['email'] != '') ? $_POST['email'] : Configuration::get('PS_SHOP_EMAIL'))); - + $this->_clearCache('blockcontactinfos.tpl'); $html .= '
'.$this->l('Configuration updated').'
'; } @@ -104,15 +105,14 @@ class Blockcontactinfos extends Module public function hookFooter($params) { - global $smarty; - - $smarty->assign(array( - 'blockcontactinfos_company' => Configuration::get('blockcontactinfos_company'), - 'blockcontactinfos_address' => Configuration::get('blockcontactinfos_address'), - 'blockcontactinfos_phone' => Configuration::get('blockcontactinfos_phone'), - 'blockcontactinfos_email' => Configuration::get('blockcontactinfos_email') - )); - return $this->display(__FILE__, 'blockcontactinfos.tpl'); + if (!$this->isCached('blockcontactinfos.tpl', $this->getCacheId())) + $smarty->assign(array( + 'blockcontactinfos_company' => Configuration::get('blockcontactinfos_company'), + 'blockcontactinfos_address' => Configuration::get('blockcontactinfos_address'), + 'blockcontactinfos_phone' => Configuration::get('blockcontactinfos_phone'), + 'blockcontactinfos_email' => Configuration::get('blockcontactinfos_email') + )); + return $this->display(__FILE__, 'blockcontactinfos.tpl', $this->getCacheId()); } } ?> diff --git a/modules/blockmyaccountfooter/blockmyaccountfooter.php b/modules/blockmyaccountfooter/blockmyaccountfooter.php index 098a74fd2..6c5b305c4 100644 --- a/modules/blockmyaccountfooter/blockmyaccountfooter.php +++ b/modules/blockmyaccountfooter/blockmyaccountfooter.php @@ -93,11 +93,12 @@ class Blockmyaccountfooter extends Module { global $smarty; - $smarty->assign(array( - 'voucherAllowed' => CartRule::isFeatureActive(), - 'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')), - 'HOOK_BLOCK_MY_ACCOUNT' => Hook::exec('displayMyAccountBlock') - )); - return $this->display(__FILE__, $this->name.'.tpl'); + if (!$this->isCached('blockmyaccountfooter.tpl', $this->getCacheId())) + $smarty->assign(array( + 'voucherAllowed' => CartRule::isFeatureActive(), + 'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')), + 'HOOK_BLOCK_MY_ACCOUNT' => Hook::exec('displayMyAccountBlock') + )); + return $this->display(__FILE__, 'blockmyaccountfooter.tpl', $this->getCacheId()); } } diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index e9fa78c1c..be984f287 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -509,13 +509,12 @@ class Blocknewsletter extends Module public function hookDisplayLeftColumn($params) { $this->_prepareHook($params); - return $this->display(__FILE__, 'blocknewsletter.tpl'); + return $this->display(__FILE__, 'blocknewsletter.tpl', $this->getCacheId()); } public function hookFooter($params) { - $this->_prepareHook($params); - return $this->display(__FILE__, 'blocknewsletter.tpl'); + return $this->hookDisplayLeftColumn($params); } public function hookDisplayHeader($params) diff --git a/modules/blockpaymentlogo/blockpaymentlogo.php b/modules/blockpaymentlogo/blockpaymentlogo.php index 8201284af..af5fa75ad 100644 --- a/modules/blockpaymentlogo/blockpaymentlogo.php +++ b/modules/blockpaymentlogo/blockpaymentlogo.php @@ -71,6 +71,7 @@ class BlockPaymentLogo extends Module if (Validate::isUnsignedInt(Tools::getValue('id_cms'))) { Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', (int)(Tools::getValue('id_cms'))); + $this->_clearCache('blockpaymentlogo.tpl'); $html .= $this->displayConfirmation($this->l('Settings are updated')); } @@ -110,14 +111,17 @@ class BlockPaymentLogo extends Module if (Configuration::get('PS_CATALOG_MODE')) return; + if (!$this->isCached('blockpaymentlogo.tpl', $this->getCacheId())) + { + if (!Configuration::get('PS_PAYMENT_LOGO_CMS_ID')) + return; + $cms = new CMS(Configuration::get('PS_PAYMENT_LOGO_CMS_ID'), $this->context->language->id); + if (!Validate::isLoadedObject($cms)) + return; + $this->smarty->assign('cms_payement_logo', $cms); + } - if (!Configuration::get('PS_PAYMENT_LOGO_CMS_ID')) - return; - $cms = new CMS(Configuration::get('PS_PAYMENT_LOGO_CMS_ID'), $this->context->language->id); - if (!Validate::isLoadedObject($cms)) - return; - $this->smarty->assign('cms_payement_logo', $cms); - return $this->display(__FILE__, 'blockpaymentlogo.tpl'); + return $this->display(__FILE__, 'blockpaymentlogo.tpl', $this->getCacheId()); } public function hookRightColumn($params) diff --git a/modules/blockpermanentlinks/blockpermanentlinks.php b/modules/blockpermanentlinks/blockpermanentlinks.php index 58b4c2c20..968b82563 100644 --- a/modules/blockpermanentlinks/blockpermanentlinks.php +++ b/modules/blockpermanentlinks/blockpermanentlinks.php @@ -56,7 +56,7 @@ class BlockPermanentLinks extends Module */ public function hookTop($params) { - return $this->display(__FILE__, 'blockpermanentlinks-header.tpl'); + return $this->display(__FILE__, 'blockpermanentlinks-header.tpl', $this->getCacheId('blockpermanentlinks-header')); } /** @@ -67,7 +67,7 @@ class BlockPermanentLinks extends Module */ public function hookLeftColumn($params) { - return $this->display(__FILE__, 'blockpermanentlinks.tpl'); + return $this->display(__FILE__, 'blockpermanentlinks.tpl', $this->getCacheId()); } public function hookRightColumn($params) @@ -77,7 +77,7 @@ class BlockPermanentLinks extends Module public function hookFooter($params) { - return $this->display(__FILE__, 'blockpermanentlinks-footer.tpl'); + return $this->display(__FILE__, 'blockpermanentlinks-footer.tpl', $this->getCacheId('blockpermanentlinks-footer')); } public function hookHeader($params) diff --git a/modules/blockreinsurance/blockreinsurance.php b/modules/blockreinsurance/blockreinsurance.php index 7fa261af3..428f3022d 100644 --- a/modules/blockreinsurance/blockreinsurance.php +++ b/modules/blockreinsurance/blockreinsurance.php @@ -19,7 +19,8 @@ * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA -* @copyright 2007-2013 PrestaShop SA +* @copyright 2007-2013 PrestaShop SA + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @@ -133,6 +134,7 @@ class Blockreinsurance extends Module { $html = ''; $id_reinsurance = (int)Tools::getValue('id_reinsurance'); + if (Tools::isSubmit('saveblockreinsurance')) { if ($id_reinsurance = Tools::getValue('id_reinsurance')) @@ -157,6 +159,7 @@ class Blockreinsurance extends Module $reinsurance->file_name = 'reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg'; $reinsurance->save(); } + $this->_clearCache('blockreinsurance.tpl'); } else $html .= '
'.$this->l('An error occurred during the save').'
'; @@ -187,6 +190,7 @@ class Blockreinsurance extends Module if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name)) unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name); $reinsurance->delete(); + $this->_clearCache('blockreinsurance.tpl'); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else @@ -199,7 +203,10 @@ class Blockreinsurance extends Module { Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : '')); if ($this->removeFromDB() && $this->addToDB()) + { + $this->_clearCache('blockreinsurance.tpl'); $output = '
'.$this->l('Configuration updated').'
'; + } else $output = '
'.$this->l('An error occurred during the save').'
'; } @@ -323,9 +330,12 @@ class Blockreinsurance extends Module return false; $this->context->controller->addCSS($this->_path.'style.css', 'all'); - $infos = $this->getListContent($this->context->language->id); - $this->context->smarty->assign(array('infos' => $infos, 'nbblocks' => count($infos))); - return $this->display(__FILE__, 'blockreinsurance.tpl'); + if (!$this->isCached('blockreinsurance.tpl', $this->getCacheId())) + { + $infos = $this->getListContent($this->context->language->id); + $this->context->smarty->assign(array('infos' => $infos, 'nbblocks' => count($infos))); + } + return $this->display(__FILE__, 'blockreinsurance.tpl', $this->getCacheId()); } public function installFixtures() diff --git a/modules/blockstore/blockstore.php b/modules/blockstore/blockstore.php index 1ef76fa5b..f9df5466d 100644 --- a/modules/blockstore/blockstore.php +++ b/modules/blockstore/blockstore.php @@ -62,14 +62,19 @@ class BlockStore extends Module public function hookRightColumn($params) { - $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG')); - $sql = 'SELECT COUNT(*) - FROM '._DB_PREFIX_.'store s' - .Shop::addSqlAssociation('store', 's'); - $total = Db::getInstance()->getValue($sql); + if (!$this->isCached('blockstore.tpl', $this->getCacheId())) + { + $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG')); + $sql = 'SELECT COUNT(*) + FROM '._DB_PREFIX_.'store s' + .Shop::addSqlAssociation('store', 's'); + $total = Db::getInstance()->getValue($sql); + + if ($total <= 0) + return; + } + return $this->display(__FILE__, 'blockstore.tpl', $this->getCacheId()); - if ($total > 0) - return $this->display(__FILE__, 'blockstore.tpl'); } public function hookHeader($params) @@ -94,6 +99,7 @@ class BlockStore extends Module if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name']) @unlink(dirname(__FILE__).'/'.Configuration::get('BLOCKSTORE_IMG')); Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']); + $this->_clearCache('blockstore.tpl'); return $this->displayConfirmation($this->l('Settings are updated')); } } diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index 9b4196f61..f73953552 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -712,15 +712,19 @@ class Blocktopmenu extends Module foreach ($pages as $page) $this->_html .= ''; } + + protected function getCacheId($name = null) + { + parent::getCacheId($name); + $page_name = in_array($this->page_name, array('category', 'supplier', 'manufacturer', 'cms', 'product')) ? $this->page_name : 'index'; + return 'blocktopmenu|'.$page_name.'-'.(int)$this->context->shop->id.'-'.implode(', ',$this->user_groups).'-'.(int)$this->context->language->id.'-'.(int)Tools::getValue('id_category').'-'.(int)Tools::getValue('id_manufacturer').'-'.(int)Tools::getValue('id_supplier').'-'.(int)Tools::getValue('id_cms').'-'.(int)Tools::getValue('id_product'); + } public function hookDisplayTop($param) { $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); $this->page_name = Dispatcher::getInstance()->getController(); - $smarty_cache_id = 'blocktopmenu-'.$this->page_name.'-'.(int)$this->context->shop->id.'-'.implode(', ',$this->user_groups).'-'.(int)$this->context->language->id.'-'.(int)Tools::getValue('id_category').'-'.(int)Tools::getValue('id_manufacturer').'-'.(int)Tools::getValue('id_supplier').'-'.(int)Tools::getValue('id_cms').'-'.(int)Tools::getValue('id_product'); - $this->context->smarty->cache_lifetime = 31536000; - Tools::enableCache(); - if (!$this->isCached('blocktopmenu.tpl', $smarty_cache_id)) + if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId())) { $this->makeMenu(); $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); @@ -732,8 +736,7 @@ class Blocktopmenu extends Module $this->context->controller->addJS($this->_path.'js/superfish-modified.js'); $this->context->controller->addCSS($this->_path.'css/superfish-modified.css'); - $html = $this->display(__FILE__, 'blocktopmenu.tpl', $smarty_cache_id); - Tools::restoreCacheSettings(); + $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId()); return $html; }