[*] MO: Add smarty cache on some modules

This commit is contained in:
Rémi Gaillard
2013-01-07 17:09:36 +01:00
parent 1f7ab4f172
commit cd89916a20
14 changed files with 136 additions and 95 deletions
+4 -1
View File
@@ -598,9 +598,12 @@ class CustomerCore extends ObjectModel
public static function getGroupsStatic($id_customer) public static function getGroupsStatic($id_customer)
{ {
if (!Group::isFeatureActive() || $id_customer == 0) if (!Group::isFeatureActive())
return array(Configuration::get('PS_CUSTOMER_GROUP')); 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])) if (!isset(self::$_customer_groups[$id_customer]))
{ {
self::$_customer_groups[$id_customer] = array(); self::$_customer_groups[$id_customer] = array();
+1
View File
@@ -1830,6 +1830,7 @@ exit;
self::$_caching = (int)$smarty->caching; self::$_caching = (int)$smarty->caching;
$smarty->force_compile = 0; $smarty->force_compile = 0;
$smarty->caching = (int)$level; $smarty->caching = (int)$level;
$smarty->cache_lifetime = 31536000; // 1 Year
} }
public static function restoreCacheSettings(Context $context = null) public static function restoreCacheSettings(Context $context = null)
+21 -4
View File
@@ -1582,11 +1582,18 @@ abstract class ModuleCore
{ {
return Module::_isTemplateOverloadedStatic($this->name, $template); 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) public function display($file, $template, $cacheId = null, $compileId = null)
{ {
if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === 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 else
{ {
$this->smarty->assign(array( $this->smarty->assign(array(
@@ -1594,16 +1601,22 @@ abstract class ModuleCore
'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/' 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/'
)); ));
if ($cacheId !== null)
Tools::enableCache();
$smarty_subtemplate = $this->context->smarty->createTemplate( $smarty_subtemplate = $this->context->smarty->createTemplate(
$this->getTemplatePath($template), $this->getTemplatePath($template),
$cacheId, $cacheId,
$compileId, $compileId,
$this->smarty $this->smarty
); );
$result = $smarty_subtemplate->fetch(); $result = $smarty_subtemplate->fetch();
if ($cacheId !== null)
Tools::restoreCacheSettings();
return $result;
} }
return $result;
} }
/** /**
@@ -1635,7 +1648,11 @@ abstract class ModuleCore
{ {
$context = Context::getContext(); $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) protected function _clearCache($template, $cache_id = null, $compile_id = null)
@@ -157,6 +157,7 @@ class BlockAdvertising extends Module
// Reset the module properties // Reset the module properties
$this->initialize(); $this->initialize();
$this->_clearCache('blockadvertising.tpl');
} }
if ($errors) if ($errors)
echo $this->displayError($errors); echo $this->displayError($errors);
@@ -216,13 +217,14 @@ class BlockAdvertising extends Module
public function hookRightColumn($params) public function hookRightColumn($params)
{ {
$this->smarty->assign(array( if (!$this->isCached('blockadvertising.tpl', $this->getCacheId()))
'image' => $this->context->link->protocol_content.$this->adv_img, $this->smarty->assign(array(
'adv_link' => $this->adv_link, 'image' => $this->context->link->protocol_content.$this->adv_img,
'adv_title' => $this->adv_title, '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) public function hookLeftColumn($params)
+24 -30
View File
@@ -156,31 +156,23 @@ class BlockCategories extends Module
} }
public function hookLeftColumn($params) public function hookLeftColumn($params)
{ {
$id_customer = (int)$params['cookie']->id_customer; if (!$this->isCached('blockcategories.tpl', $this->getCacheId()))
// 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))
{ {
// 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'); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c 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.') 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').') WHERE (c.`active` = 1 OR c.`id_category` = '.(int)Configuration::get('PS_HOME_CATEGORY').')
AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').' AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').'
'.((int)$maxdepth != 0 ? ' AND `level_depth` <= '.(int)$maxdepth : '').' '.((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).')) 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'))) 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(); $resultParents = array();
$resultIds = array(); $resultIds = array();
@@ -203,7 +195,7 @@ class BlockCategories extends Module
if (Tools::isSubmit('id_product')) if (Tools::isSubmit('id_product'))
{ {
if (!isset($this->context->cookie->last_visited_category) 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)) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop))
{ {
$product = new Product($id_product); $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('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$this->smarty->assign('isDhtml', $isDhtml); $this->smarty->assign('isDhtml', $isDhtml);
} }
$display = $this->display(__FILE__, 'blockcategories.tpl', $smartyCacheId); $display = $this->display(__FILE__, 'blockcategories.tpl', $this->getCacheId());
Tools::restoreCacheSettings();
return $display; 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) 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..." // 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_; if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId()))
$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))
{ {
$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); $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(' if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c FROM `'._DB_PREFIX_.'category` c
'.Shop::addSqlAssociation('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`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1) WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' '.((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('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$this->smarty->assign('isDhtml', $isDhtml); $this->smarty->assign('isDhtml', $isDhtml);
} }
$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId); $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $this->getCacheId());
Tools::restoreCacheSettings();
return $display; return $display;
} }
+8 -7
View File
@@ -19,7 +19,7 @@
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @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) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * 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_telnumber', Tools::getValue('telnumber'));
Configuration::updateValue('blockcontact_email', Tools::getValue('email')); Configuration::updateValue('blockcontact_email', Tools::getValue('email'));
$this->_clearCache('blockcontact.tpl');
$html .= '<div class="conf confirm">'.$this->l('Configuration updated').'</div>'; $html .= '<div class="conf confirm">'.$this->l('Configuration updated').'</div>';
} }
@@ -94,12 +95,12 @@ class Blockcontact extends Module
public function hookDisplayRightColumn() public function hookDisplayRightColumn()
{ {
global $smarty; global $smarty;
if (!$this->isCached('blockcontact.tpl', $this->getCacheId()))
$smarty->assign(array( $smarty->assign(array(
'telnumber' => Configuration::get('blockcontact_telnumber'), 'telnumber' => Configuration::get('blockcontact_telnumber'),
'email' => Configuration::get('blockcontact_email') 'email' => Configuration::get('blockcontact_email')
)); ));
return $this->display(__FILE__, 'blockcontact.tpl'); return $this->display(__FILE__, 'blockcontact.tpl', $this->getCacheId());
} }
public function hookDisplayLeftColumn() public function hookDisplayLeftColumn()
+11 -11
View File
@@ -19,7 +19,8 @@
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @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) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * 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_address', ((isset($_POST['address']) && $_POST['address'] != '') ? $_POST['address'] : ''));
Configuration::updateValue('blockcontactinfos_phone', ((isset($_POST['phone']) && $_POST['phone'] != '') ? $_POST['phone'] : '')); 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'))); Configuration::updateValue('blockcontactinfos_email', ((isset($_POST['email']) && $_POST['email'] != '') ? $_POST['email'] : Configuration::get('PS_SHOP_EMAIL')));
$this->_clearCache('blockcontactinfos.tpl');
$html .= '<div class="conf confirm">'.$this->l('Configuration updated').'</div>'; $html .= '<div class="conf confirm">'.$this->l('Configuration updated').'</div>';
} }
@@ -104,15 +105,14 @@ class Blockcontactinfos extends Module
public function hookFooter($params) public function hookFooter($params)
{ {
global $smarty; if (!$this->isCached('blockcontactinfos.tpl', $this->getCacheId()))
$smarty->assign(array(
$smarty->assign(array( 'blockcontactinfos_company' => Configuration::get('blockcontactinfos_company'),
'blockcontactinfos_company' => Configuration::get('blockcontactinfos_company'), 'blockcontactinfos_address' => Configuration::get('blockcontactinfos_address'),
'blockcontactinfos_address' => Configuration::get('blockcontactinfos_address'), 'blockcontactinfos_phone' => Configuration::get('blockcontactinfos_phone'),
'blockcontactinfos_phone' => Configuration::get('blockcontactinfos_phone'), 'blockcontactinfos_email' => Configuration::get('blockcontactinfos_email')
'blockcontactinfos_email' => Configuration::get('blockcontactinfos_email') ));
)); return $this->display(__FILE__, 'blockcontactinfos.tpl', $this->getCacheId());
return $this->display(__FILE__, 'blockcontactinfos.tpl');
} }
} }
?> ?>
@@ -93,11 +93,12 @@ class Blockmyaccountfooter extends Module
{ {
global $smarty; global $smarty;
$smarty->assign(array( if (!$this->isCached('blockmyaccountfooter.tpl', $this->getCacheId()))
'voucherAllowed' => CartRule::isFeatureActive(), $smarty->assign(array(
'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')), 'voucherAllowed' => CartRule::isFeatureActive(),
'HOOK_BLOCK_MY_ACCOUNT' => Hook::exec('displayMyAccountBlock') 'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')),
)); 'HOOK_BLOCK_MY_ACCOUNT' => Hook::exec('displayMyAccountBlock')
return $this->display(__FILE__, $this->name.'.tpl'); ));
return $this->display(__FILE__, 'blockmyaccountfooter.tpl', $this->getCacheId());
} }
} }
+2 -3
View File
@@ -509,13 +509,12 @@ class Blocknewsletter extends Module
public function hookDisplayLeftColumn($params) public function hookDisplayLeftColumn($params)
{ {
$this->_prepareHook($params); $this->_prepareHook($params);
return $this->display(__FILE__, 'blocknewsletter.tpl'); return $this->display(__FILE__, 'blocknewsletter.tpl', $this->getCacheId());
} }
public function hookFooter($params) public function hookFooter($params)
{ {
$this->_prepareHook($params); return $this->hookDisplayLeftColumn($params);
return $this->display(__FILE__, 'blocknewsletter.tpl');
} }
public function hookDisplayHeader($params) public function hookDisplayHeader($params)
+11 -7
View File
@@ -71,6 +71,7 @@ class BlockPaymentLogo extends Module
if (Validate::isUnsignedInt(Tools::getValue('id_cms'))) if (Validate::isUnsignedInt(Tools::getValue('id_cms')))
{ {
Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', (int)(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')); $html .= $this->displayConfirmation($this->l('Settings are updated'));
} }
@@ -110,14 +111,17 @@ class BlockPaymentLogo extends Module
if (Configuration::get('PS_CATALOG_MODE')) if (Configuration::get('PS_CATALOG_MODE'))
return; 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 $this->display(__FILE__, 'blockpaymentlogo.tpl', $this->getCacheId());
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');
} }
public function hookRightColumn($params) public function hookRightColumn($params)
@@ -56,7 +56,7 @@ class BlockPermanentLinks extends Module
*/ */
public function hookTop($params) 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) public function hookLeftColumn($params)
{ {
return $this->display(__FILE__, 'blockpermanentlinks.tpl'); return $this->display(__FILE__, 'blockpermanentlinks.tpl', $this->getCacheId());
} }
public function hookRightColumn($params) public function hookRightColumn($params)
@@ -77,7 +77,7 @@ class BlockPermanentLinks extends Module
public function hookFooter($params) 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) public function hookHeader($params)
+14 -4
View File
@@ -19,7 +19,8 @@
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @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) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
@@ -133,6 +134,7 @@ class Blockreinsurance extends Module
{ {
$html = ''; $html = '';
$id_reinsurance = (int)Tools::getValue('id_reinsurance'); $id_reinsurance = (int)Tools::getValue('id_reinsurance');
if (Tools::isSubmit('saveblockreinsurance')) if (Tools::isSubmit('saveblockreinsurance'))
{ {
if ($id_reinsurance = Tools::getValue('id_reinsurance')) 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->file_name = 'reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg';
$reinsurance->save(); $reinsurance->save();
} }
$this->_clearCache('blockreinsurance.tpl');
} }
else else
$html .= '<div class="conf error">'.$this->l('An error occurred during the save').'</div>'; $html .= '<div class="conf error">'.$this->l('An error occurred during the save').'</div>';
@@ -187,6 +190,7 @@ class Blockreinsurance extends Module
if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name)) if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name))
unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name); unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name);
$reinsurance->delete(); $reinsurance->delete();
$this->_clearCache('blockreinsurance.tpl');
Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'));
} }
else else
@@ -199,7 +203,10 @@ class Blockreinsurance extends Module
{ {
Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : '')); Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : ''));
if ($this->removeFromDB() && $this->addToDB()) if ($this->removeFromDB() && $this->addToDB())
{
$this->_clearCache('blockreinsurance.tpl');
$output = '<div class="conf confirm">'.$this->l('Configuration updated').'</div>'; $output = '<div class="conf confirm">'.$this->l('Configuration updated').'</div>';
}
else else
$output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred during the save').'</div>'; $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred during the save').'</div>';
} }
@@ -323,9 +330,12 @@ class Blockreinsurance extends Module
return false; return false;
$this->context->controller->addCSS($this->_path.'style.css', 'all'); $this->context->controller->addCSS($this->_path.'style.css', 'all');
$infos = $this->getListContent($this->context->language->id); if (!$this->isCached('blockreinsurance.tpl', $this->getCacheId()))
$this->context->smarty->assign(array('infos' => $infos, 'nbblocks' => count($infos))); {
return $this->display(__FILE__, 'blockreinsurance.tpl'); $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() public function installFixtures()
+13 -7
View File
@@ -62,14 +62,19 @@ class BlockStore extends Module
public function hookRightColumn($params) public function hookRightColumn($params)
{ {
$this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG')); if (!$this->isCached('blockstore.tpl', $this->getCacheId()))
$sql = 'SELECT COUNT(*) {
FROM '._DB_PREFIX_.'store s' $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG'));
.Shop::addSqlAssociation('store', 's'); $sql = 'SELECT COUNT(*)
$total = Db::getInstance()->getValue($sql); 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) 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']) if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name'])
@unlink(dirname(__FILE__).'/'.Configuration::get('BLOCKSTORE_IMG')); @unlink(dirname(__FILE__).'/'.Configuration::get('BLOCKSTORE_IMG'));
Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']); Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']);
$this->_clearCache('blockstore.tpl');
return $this->displayConfirmation($this->l('Settings are updated')); return $this->displayConfirmation($this->l('Settings are updated'));
} }
} }
+9 -6
View File
@@ -712,15 +712,19 @@ class Blocktopmenu extends Module
foreach ($pages as $page) foreach ($pages as $page)
$this->_html .= '<option value="CMS'.$page['id_cms'].'">'.$spacer.$page['meta_title'].'</option>'; $this->_html .= '<option value="CMS'.$page['id_cms'].'">'.$spacer.$page['meta_title'].'</option>';
} }
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) public function hookDisplayTop($param)
{ {
$this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP')));
$this->page_name = Dispatcher::getInstance()->getController(); $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'); if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId()))
$this->context->smarty->cache_lifetime = 31536000;
Tools::enableCache();
if (!$this->isCached('blocktopmenu.tpl', $smarty_cache_id))
{ {
$this->makeMenu(); $this->makeMenu();
$this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); $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->addJS($this->_path.'js/superfish-modified.js');
$this->context->controller->addCSS($this->_path.'css/superfish-modified.css'); $this->context->controller->addCSS($this->_path.'css/superfish-modified.css');
$html = $this->display(__FILE__, 'blocktopmenu.tpl', $smarty_cache_id); $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId());
Tools::restoreCacheSettings();
return $html; return $html;
} }