From 4a8f2f8970d1c848337207f6b37d6b53450ff47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Mon, 7 Jan 2013 17:39:06 +0100 Subject: [PATCH] [*] MO: Add smarty cache on homeslider --- modules/homeslider/ajax_homeslider.php | 2 ++ modules/homeslider/homeslider.php | 40 +++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/modules/homeslider/ajax_homeslider.php b/modules/homeslider/ajax_homeslider.php index 381d0a18a..00f994605 100644 --- a/modules/homeslider/ajax_homeslider.php +++ b/modules/homeslider/ajax_homeslider.php @@ -47,5 +47,7 @@ if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slid ); } + + $home_slider->clearCache(); } diff --git a/modules/homeslider/homeslider.php b/modules/homeslider/homeslider.php index 66266dac5..45ab0b77b 100644 --- a/modules/homeslider/homeslider.php +++ b/modules/homeslider/homeslider.php @@ -518,6 +518,7 @@ class HomeSlider extends Module $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int)Tools::getValue('HOMESLIDER_SPEED')); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int)Tools::getValue('HOMESLIDER_PAUSE')); $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int)Tools::getValue('HOMESLIDER_LOOP')); + $this->clearCache(); if (!$res) $errors[] = $this->displayError($this->l('Configuration could not be updated')); $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); @@ -530,6 +531,7 @@ class HomeSlider extends Module else $slide->active = 0; $res = $slide->update(); + $this->clearCache(); $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('Configuration could not be updated'))); } /* Processes Slide */ @@ -602,12 +604,14 @@ class HomeSlider extends Module } /* Update */ elseif (!$slide->update()) $errors[] = $this->displayError($this->l('Slide could not be updated')); + $this->clearCache(); } } /* Deletes */ elseif (Tools::isSubmit('delete_id_slide')) { $slide = new HomeSlide((int)Tools::getValue('delete_id_slide')); $res = $slide->delete(); + $this->clearCache(); if (!$res) $this->_html .= $this->displayError('Could not delete'); else @@ -625,20 +629,24 @@ class HomeSlider extends Module private function _prepareHook() { - $slider = array( - 'width' => Configuration::get('HOMESLIDER_WIDTH'), - 'height' => Configuration::get('HOMESLIDER_HEIGHT'), - 'speed' => Configuration::get('HOMESLIDER_SPEED'), - 'pause' => Configuration::get('HOMESLIDER_PAUSE'), - 'loop' => Configuration::get('HOMESLIDER_LOOP'), - ); + if (!$this->isCached('homeslider.tpl', $this->getCacheId())) + { + $slider = array( + 'width' => Configuration::get('HOMESLIDER_WIDTH'), + 'height' => Configuration::get('HOMESLIDER_HEIGHT'), + 'speed' => Configuration::get('HOMESLIDER_SPEED'), + 'pause' => Configuration::get('HOMESLIDER_PAUSE'), + 'loop' => Configuration::get('HOMESLIDER_LOOP'), + ); - $slides = $this->getSlides(true); - if (!$slides) - return false; + $slides = $this->getSlides(true); + if (!$slides) + return false; + + $this->smarty->assign('homeslider_slides', $slides); + $this->smarty->assign('homeslider', $slider); + } - $this->smarty->assign('homeslider_slides', $slides); - $this->smarty->assign('homeslider', $slider); return true; } @@ -654,7 +662,12 @@ class HomeSlider extends Module $this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js'); $this->context->controller->addCSS($this->_path.'bx_styles.css'); $this->context->controller->addJS($this->_path.'js/homeslider.js'); - return $this->display(__FILE__, 'homeslider.tpl'); + return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId()); + } + + public function clearCache() + { + $this->_clearCache('homeslider.tpl'); } public function hookActionShopDataDuplication($params) @@ -664,6 +677,7 @@ class HomeSlider extends Module SELECT id_homeslider_slides, '.(int)$params['new_id_shop'].' FROM '._DB_PREFIX_.'homeslider WHERE id_shop = '.(int)$params['old_id_shop']); + $this->clearCache(); } public function headerHTML()