diff --git a/modules/blocknewproducts/blocknewproducts.php b/modules/blocknewproducts/blocknewproducts.php index 398ea29e2..4fa329db7 100644 --- a/modules/blocknewproducts/blocknewproducts.php +++ b/modules/blocknewproducts/blocknewproducts.php @@ -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'); + } +} \ No newline at end of file diff --git a/modules/blocknewproducts/config.xml b/modules/blocknewproducts/config.xml index f24ddb73f..6be6c8dd0 100755 --- a/modules/blocknewproducts/config.xml +++ b/modules/blocknewproducts/config.xml @@ -2,7 +2,7 @@ blocknewproducts - + diff --git a/modules/blocknewproducts/upgrade/install-1.0.php b/modules/blocknewproducts/upgrade/install-1.0.php new file mode 100644 index 000000000..ed388519f --- /dev/null +++ b/modules/blocknewproducts/upgrade/install-1.0.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct')); +}