diff --git a/modules/homefeatured/config.xml b/modules/homefeatured/config.xml index fa546c282..cd700c29d 100755 --- a/modules/homefeatured/config.xml +++ b/modules/homefeatured/config.xml @@ -1,9 +1,9 @@ homefeatured - - - + + + 1 diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 4567adfa1..2657134d5 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -36,7 +36,7 @@ class HomeFeatured extends Module { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; - $this->version = '0.9'; + $this->version = '1.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -48,17 +48,31 @@ class HomeFeatured extends Module function install() { - if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header')) + $this->_clearCache('homefeatured.tpl'); + if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) + || !parent::install() + || !$this->registerHook('displayHome') + || !$this->registerHook('header') + || !$this->registerHook('addproduct') + || !$this->registerHook('updateproduct') + || !$this->registerHook('deleteproduct') + ) return false; return true; } + + public function uninstall() + { + $this->_clearCache('homefeatured.tpl'); + return parent::uninstall(); + } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitHomeFeatured')) { - $nbr = (int)(Tools::getValue('nbr')); + $nbr = (int)Tools::getValue('nbr'); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('An invalid number of products has been specified.'); else @@ -101,16 +115,34 @@ class HomeFeatured extends Module public function hookDisplayHome($params) { - $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)); + 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)); - $this->smarty->assign(array( - 'products' => $products, - 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), - 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), - )); - - return $this->display(__FILE__, 'homefeatured.tpl'); + $this->smarty->assign(array( + 'products' => $products, + 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), + 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), + )); + } + return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } -} + + public function hookAddProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } + + public function hookUpdateProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } + + public function hookDeleteProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } +} \ No newline at end of file diff --git a/modules/homefeatured/upgrade/install-1.0.php b/modules/homefeatured/upgrade/install-1.0.php new file mode 100644 index 000000000..ed388519f --- /dev/null +++ b/modules/homefeatured/upgrade/install-1.0.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct')); +}