diff --git a/modules/blockbestsellers/blockbestsellers.php b/modules/blockbestsellers/blockbestsellers.php index 8f736e448..58b79ff51 100644 --- a/modules/blockbestsellers/blockbestsellers.php +++ b/modules/blockbestsellers/blockbestsellers.php @@ -36,7 +36,7 @@ class BlockBestSellers extends Module { $this->name = 'blockbestsellers'; $this->tab = 'front_office_features'; - $this->version = '1.1'; + $this->version = '1.2'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -51,14 +51,53 @@ class BlockBestSellers extends Module */ public function install() { - if (!parent::install() || - !$this->registerHook('rightColumn') || - !$this->registerHook('header') || - !$this->registerHook('updateOrderStatus') || - !ProductSale::fillProductSales()) + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + + if (!parent::install() + || !$this->registerHook('rightColumn') + || !$this->registerHook('header') + || !$this->registerHook('actionOrderStatusPostUpdate') + || !$this->registerHook('addproduct') + || !$this->registerHook('updateproduct') + || !$this->registerHook('deleteproduct') + || !ProductSale::fillProductSales() + ) return false; return true; } + + public function uninstall() + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + + return parent::uninstall(); + } + + public function hookAddProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookUpdateProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookDeleteProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookActionOrderStatusPostUpdate($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } /** * Called in administration -> module -> configure @@ -102,28 +141,34 @@ class BlockBestSellers extends Module public function hookHome($params) { - $best_sellers = $this->getBestSellers($params); - if ($best_sellers === false) - return; + if (!$this->isCached('blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home'))) + { + $best_sellers = $this->getBestSellers($params); + if ($best_sellers === false) + return; - $this->smarty->assign(array( - 'best_sellers' => $best_sellers, - 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); - return $this->display(__FILE__, 'blockbestsellers-home.tpl'); + $this->smarty->assign(array( + 'best_sellers' => $best_sellers, + 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); + } + return $this->display(__FILE__, 'blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home')); } public function hookRightColumn($params) { - $best_sellers = $this->getBestSellers($params); - if ($best_sellers === false) - return; + if (!$this->isCached('blockbestsellers.tpl', $this->getCacheId('blockbestsellers'))) + { + $best_sellers = $this->getBestSellers($params); + if ($best_sellers === false) + return; - $this->smarty->assign(array( - 'best_sellers' => $best_sellers, - 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), - 'smallSize' => Image::getSize(ImageType::getFormatedName('small')) - )); - return $this->display(__FILE__, 'blockbestsellers.tpl'); + $this->smarty->assign(array( + 'best_sellers' => $best_sellers, + 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), + 'smallSize' => Image::getSize(ImageType::getFormatedName('small')) + )); + } + return $this->display(__FILE__, 'blockbestsellers.tpl', $this->getCacheId('blockbestsellers')); } public function hookLeftColumn($params) @@ -136,7 +181,7 @@ class BlockBestSellers extends Module if (Configuration::get('PS_CATALOG_MODE')) return false; - if (!($result = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5))) + if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, 5))) return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false); $bestsellers = array(); diff --git a/modules/blockbestsellers/config.xml b/modules/blockbestsellers/config.xml index b8141299b..b8a2515a0 100755 --- a/modules/blockbestsellers/config.xml +++ b/modules/blockbestsellers/config.xml @@ -2,7 +2,7 @@ blockbestsellers - + diff --git a/modules/blockbestsellers/upgrade/install-1.2.php b/modules/blockbestsellers/upgrade/install-1.2.php new file mode 100644 index 000000000..1c636719c --- /dev/null +++ b/modules/blockbestsellers/upgrade/install-1.2.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct') && $object->registerHook('actionOrderStatusPostUpdate')); +} diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 2657134d5..380b407b0 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -49,8 +49,9 @@ class HomeFeatured extends Module function install() { $this->_clearCache('homefeatured.tpl'); - if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) - || !parent::install() + Configuration::updateValue('HOME_FEATURED_NBR', 8); + + if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header') || !$this->registerHook('addproduct') @@ -117,7 +118,6 @@ class HomeFeatured extends Module { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { - p('no cache'); $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));