[*] FO : added smarty cache on blocknewproducts

This commit is contained in:
Damien Metzger
2013-06-28 15:17:53 +02:00
parent 42f8a0a67a
commit 8acf308639
3 changed files with 57 additions and 13 deletions
+47 -12
View File
@@ -33,7 +33,7 @@ class BlockNewProducts extends Module
{
$this->name = 'blocknewproducts';
$this->tab = 'front_office_features';
$this->version = 0.9;
$this->version = 1.0;
$this->author = 'PrestaShop';
$this->need_instance = 0;
@@ -45,9 +45,23 @@ class BlockNewProducts extends Module
public function install()
{
if (parent::install() == false || $this->registerHook('rightColumn') == false || $this->registerHook('header') == false || Configuration::updateValue('NEW_PRODUCTS_NBR', 5) == false)
return false;
return true;
if (!parent::install()
|| !$this->registerHook('rightColumn')
|| !$this->registerHook('header')
|| !$this->registerHook('addproduct')
|| !$this->registerHook('updateproduct')
|| !$this->registerHook('deleteproduct')
|| !Configuration::updateValue('NEW_PRODUCTS_NBR', 5)
)
return false;
$this->_clearCache('blocknewproducts.tpl');
return true;
}
public function uninstall()
{
$this->_clearCache('blocknewproducts.tpl');
return parent::uninstall();
}
public function getContent()
@@ -95,16 +109,25 @@ class BlockNewProducts extends Module
public function hookRightColumn($params)
{
$newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)(Configuration::get('NEW_PRODUCTS_NBR')));
if (!$newProducts && !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
return;
$this->smarty->assign(array(
'new_products' => $newProducts,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
if (!$this->isCached('blocknewproducts.tpl', $this->getCacheId()))
{
if (!($newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)Configuration::get('NEW_PRODUCTS_NBR'))))
return;
return $this->display(__FILE__, 'blocknewproducts.tpl');
$this->smarty->assign(array(
'new_products' => $newProducts,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
}
return $this->display(__FILE__, 'blocknewproducts.tpl', $this->getCacheId());
}
protected function getCacheId($name = null)
{
return parent::getCacheId('blocknewproducts|'.date('Ymd'));
}
public function hookLeftColumn($params)
@@ -117,6 +140,18 @@ class BlockNewProducts extends Module
$this->context->controller->addCSS(($this->_path).'blocknewproducts.css', 'all');
}
}
public function hookAddProduct($params)
{
$this->_clearCache('blocknewproducts.tpl');
}
public function hookUpdateProduct($params)
{
$this->_clearCache('blocknewproducts.tpl');
}
public function hookDeleteProduct($params)
{
$this->_clearCache('blocknewproducts.tpl');
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<module>
<name>blocknewproducts</name>
<displayName><![CDATA[New products block]]></displayName>
<version><![CDATA[0.9]]></version>
<version><![CDATA[1.0]]></version>
<description><![CDATA[Displays a block featuring your store&#039;s newest products.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
@@ -0,0 +1,9 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_0($object)
{
return ($object->registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
}