'.$this->l('Show the block even if no product is available.').'
+
+
+
+
'.$this->l('Specials are displayed randomly on the front end, but since it takes a lot of ressources, it is better to cache the results. Cache is reset everyday. 0 will disable the cache.').'
+
';
@@ -84,18 +106,24 @@ class BlockSpecials extends Module
public function hookRightColumn($params)
{
if (Configuration::get('PS_CATALOG_MODE'))
- return ;
-
- if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return;
+
+ // We need to create multiple caches because the products are sorted randomly
+ $random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1)));
- $this->smarty->assign(array(
- 'special' => $special,
- 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
- 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
- ));
+ if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
+ {
+ if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
+ return;
- return $this->display(__FILE__, 'blockspecials.tpl');
+ $this->smarty->assign(array(
+ 'special' => $special,
+ 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
+ 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
+ ));
+ }
+
+ return $this->display(__FILE__, 'blockspecials.tpl', $this->getCacheId('blockspecials|'.$random));
}
public function hookLeftColumn($params)
@@ -109,5 +137,19 @@ class BlockSpecials extends Module
return ;
$this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all');
}
-}
+ public function hookAddProduct($params)
+ {
+ $this->_clearCache('blockspecials.tpl');
+ }
+
+ public function hookUpdateProduct($params)
+ {
+ $this->_clearCache('blockspecials.tpl');
+ }
+
+ public function hookDeleteProduct($params)
+ {
+ $this->_clearCache('blockspecials.tpl');
+ }
+}
\ No newline at end of file
diff --git a/modules/blockspecials/config.xml b/modules/blockspecials/config.xml
index e903067d0..613f0cc76 100755
--- a/modules/blockspecials/config.xml
+++ b/modules/blockspecials/config.xml
@@ -2,7 +2,7 @@
blockspecials
-
+
diff --git a/modules/blockspecials/upgrade/install-1.0.php b/modules/blockspecials/upgrade/install-1.0.php
new file mode 100644
index 000000000..3dbc3bfe0
--- /dev/null
+++ b/modules/blockspecials/upgrade/install-1.0.php
@@ -0,0 +1,10 @@
+registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
+}