12613 - fs cache private sales home and homecat
This commit is contained in:
parent
edc744f5d5
commit
aac5a862b4
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,6 +34,8 @@ cache/tcpdf/*
|
||||
!cache/tcpdf/index.php
|
||||
tools/smarty*/cache/*.php
|
||||
!tools/smarty*/cache/index.php
|
||||
modules/privatesales/cache/*
|
||||
!modules/privatesales/cache/index.php
|
||||
|
||||
#### CONFIG ####
|
||||
config/settings.*.php
|
||||
|
36
modules/privatesales/cache/index.php
vendored
Normal file
36
modules/privatesales/cache/index.php
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
@ -34,14 +34,10 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController {
|
||||
*
|
||||
*/
|
||||
public function initContent(){
|
||||
|
||||
if(!$this->context->cookie->logged && !Configuration::get('PRIVATESALES_LISTING_PUBLIC')){
|
||||
Tools::redirect($this->context->link->getPageLink('authentication',null,$this->context->cookie->id_lang,'ps=0&back='.$this->context->link->getModuleLink('privatesales', 'home')));
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$categories = SaleCategory::getCategory();
|
||||
$news = null;
|
||||
if(Tools::getValue('type') == "nouveautes"){
|
||||
$news = 1;
|
||||
@ -49,6 +45,21 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController {
|
||||
$news = 2;
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->setTemplate('privatesales-home.tpl');
|
||||
|
||||
// 12613 - Optimisation
|
||||
$sale_cache = new SaleCache($this->context->smarty, ($news ? "home_".$news : 'home'));
|
||||
if ($sale_cache->isCached($this->template)) {
|
||||
$this->setCacheHtml($sale_cache->getCache());
|
||||
return;
|
||||
}
|
||||
// 12613 - End optimisation
|
||||
|
||||
|
||||
$categories = SaleCategory::getCategory();
|
||||
|
||||
if(Configuration::get('PRIVATESALES_FLASH'))
|
||||
$flashsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',FALSE,TRUE);
|
||||
else
|
||||
@ -156,8 +167,8 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController {
|
||||
'banner_concour_title_2' => Configuration::get('PRIVATESALES_BANNER_TITLE_CONCOURS_2'),
|
||||
'banner_concour_link_active' => Configuration::get('PRIVATESALES_BANNER_LINK_CONCOURS_ACTIVE'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->setTemplate('privatesales-home.tpl');
|
||||
}
|
||||
}
|
@ -59,6 +59,15 @@ class privatesaleshomecatModuleFrontController extends ModuleFrontController {
|
||||
}
|
||||
}
|
||||
|
||||
$this->setTemplate('privatesales-home.tpl');
|
||||
|
||||
// 12613 - Optimisation
|
||||
$sale_cache = new SaleCache($this->context->smarty, 'homecat');
|
||||
if ($sale_cache->isCached($this->template)) {
|
||||
$this->setCacheHtml($sale_cache->getCache());
|
||||
return;
|
||||
}
|
||||
// 12613 - End optimisation
|
||||
|
||||
if(Configuration::get('PRIVATESALES_FLASH'))
|
||||
$flashsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',$id_category,TRUE);
|
||||
@ -108,7 +117,6 @@ class privatesaleshomecatModuleFrontController extends ModuleFrontController {
|
||||
'link_img' => __PS_BASE_URI__.'modules/privatesales/img/',
|
||||
'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/'
|
||||
));
|
||||
$this->setTemplate('privatesales-home.tpl');
|
||||
}
|
||||
|
||||
public function ajaxProcessSubmitAlert(){
|
||||
|
51
modules/privatesales/models/SaleCache.php
Normal file
51
modules/privatesales/models/SaleCache.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
class SaleCache
|
||||
{
|
||||
private $cache_id = '';
|
||||
private $smarty = null;
|
||||
private $max_filemtime = 0;
|
||||
private $template_path = '';
|
||||
private $path_cache_file = '';
|
||||
|
||||
function __construct($smarty, $cache_prefix, $lifetime = 7200) // 2 Hours
|
||||
{
|
||||
$d = new DateTime();
|
||||
|
||||
if (isset($_SERVER['QUERY_STRING'])) {
|
||||
$cache_prefix .= $_SERVER['QUERY_STRING'];
|
||||
}
|
||||
$this->cache_id = md5("private_sales_".$cache_prefix."_".$d->format('Ymd'));
|
||||
$this->max_filemtime = $d->getTimestamp() - $lifetime;
|
||||
$this->path_cache_file = __DIR__.'/../cache/'.$this->cache_id;
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
if (!empty($this->template_path && $this->smarty)) {
|
||||
file_put_contents($this->path_cache_file, $this->smarty->fetch($this->template_path));
|
||||
}
|
||||
}
|
||||
|
||||
function isCached($template_path)
|
||||
{
|
||||
if (file_exists($this->path_cache_file) && filemtime($this->path_cache_file) > $this->max_filemtime) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->template_path = $template_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
function getCache()
|
||||
{
|
||||
return file_get_contents($this->path_cache_file);
|
||||
}
|
||||
|
||||
static function clearAll()
|
||||
{
|
||||
foreach(glob(__DIR__.'/../cache/*') as $path_file) {
|
||||
@unlink($path_file);
|
||||
}
|
||||
}
|
||||
}
|
@ -268,6 +268,10 @@ class SaleCore extends ObjectModel{
|
||||
$hist->add();
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
SaleCache::clearAll();
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
/**
|
||||
@ -909,8 +913,13 @@ class SaleCore extends ObjectModel{
|
||||
AND `id_privatesales` = '.(int)$moved_privatesales['id_privatesales'];
|
||||
|
||||
|
||||
return (Db::getInstance()->execute($sql)
|
||||
$result = (Db::getInstance()->execute($sql)
|
||||
&& Db::getInstance()->execute($sql2));
|
||||
|
||||
if ($result) {
|
||||
SaleCache::clearAll();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMail.php');
|
||||
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMailCat.php');
|
||||
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCategory.php');
|
||||
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleHistorique.php');
|
||||
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCache.php');
|
||||
|
||||
class Privatesales extends Module {
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
class FrontController extends FrontControllerCore
|
||||
{
|
||||
private $_cache_html = null;
|
||||
|
||||
public $real_page_name = '';
|
||||
|
||||
public function setMedia()
|
||||
@ -176,4 +178,72 @@ class FrontController extends FrontControllerCore
|
||||
$this->context->smarty->assign('link_conditions', $link_conditions);
|
||||
}
|
||||
|
||||
|
||||
public function display()
|
||||
{
|
||||
Tools::safePostVars();
|
||||
|
||||
// assign css_files and js_files at the very last time
|
||||
if ((Configuration::get('PS_CSS_THEME_CACHE') || Configuration::get('PS_JS_THEME_CACHE')) && is_writable(_PS_THEME_DIR_.'cache'))
|
||||
{
|
||||
// CSS compressor management
|
||||
if (Configuration::get('PS_CSS_THEME_CACHE'))
|
||||
$this->css_files = Media::cccCSS($this->css_files);
|
||||
//JS compressor management
|
||||
if (Configuration::get('PS_JS_THEME_CACHE') && !$this->useMobileTheme())
|
||||
$this->js_files = Media::cccJs($this->js_files);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'css_files' => $this->css_files,
|
||||
'js_files' => ($this->getLayout() && (bool)Configuration::get('PS_JS_DEFER')) ? array() : $this->js_files,
|
||||
'js_defer' => (bool)Configuration::get('PS_JS_DEFER'),
|
||||
'errors' => $this->errors,
|
||||
'display_header' => $this->display_header,
|
||||
'display_footer' => $this->display_footer,
|
||||
));
|
||||
$layout = $this->getLayout();
|
||||
if ($layout)
|
||||
{
|
||||
// 12613 - Optimisation
|
||||
if ($this->_cache_html!==null) {
|
||||
$template = $this->_cache_html;
|
||||
}
|
||||
// 12613 - End optimisation
|
||||
else if ($this->template){
|
||||
$template = $this->context->smarty->fetch($this->template);
|
||||
}
|
||||
else // For retrocompatibility with 1.4 controller
|
||||
{
|
||||
ob_start();
|
||||
$this->displayContent();
|
||||
$template = ob_get_contents();
|
||||
ob_clean();
|
||||
|
||||
}
|
||||
$template = $this->context->smarty->assign('template', $template);
|
||||
$this->smartyOutputContent($layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tools::displayAsDeprecated('layout.tpl is missing in your theme directory');
|
||||
if ($this->display_header)
|
||||
$this->smartyOutputContent(_PS_THEME_DIR_.'header.tpl');
|
||||
|
||||
if ($this->template)
|
||||
$this->smartyOutputContent($this->template);
|
||||
else // For retrocompatibility with 1.4 controller
|
||||
$this->displayContent();
|
||||
|
||||
if ($this->display_footer)
|
||||
$this->smartyOutputContent(_PS_THEME_DIR_.'footer.tpl');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// antadis 12613
|
||||
public function setCacheHtml($cache_html)
|
||||
{
|
||||
$this->_cache_html = $cache_html;
|
||||
}
|
||||
}
|
@ -30,13 +30,13 @@ $(document).ready(function() {
|
||||
{/capture}
|
||||
|
||||
<ul class="snotmobile nav-privatesales clearfix">
|
||||
<li {if $news === null }class="active"{/if} >
|
||||
<li {if isset($news) && $news === null }class="active"{/if} >
|
||||
<a href="{$link_allsale}" >{l s='See all sales' mod='privatesales'}</a>
|
||||
</li>
|
||||
<li {if $news == 2 }class="active"{/if}>
|
||||
<li {if isset($news) && $news == 2 }class="active"{/if}>
|
||||
<a href="{$link_allsale}?type=ventes" >{l s='sales' mod='privatesales'}</a>
|
||||
</li>
|
||||
<li {if $news == 1 }class="active"{/if}>
|
||||
<li {if isset($news) && $news == 1 }class="active"{/if}>
|
||||
<a href="{$link_allsale}?type=nouveautes" >{l s='See all news' mod='privatesales'}</a>
|
||||
</li>
|
||||
<li >
|
||||
|
Loading…
Reference in New Issue
Block a user