[*] FO : added smarty cache on homefeatured module

This commit is contained in:
Damien Metzger
2013-06-28 17:19:06 +02:00
parent a8d96ed0c0
commit 583346bbb7
3 changed files with 58 additions and 17 deletions

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>homefeatured</name>
<displayName><![CDATA[Featured products on the homepage.]]></displayName>
<version><![CDATA[0.9]]></version>
<description><![CDATA[Displays featured products in the middle of your homepage.]]></description>
<displayName><![CDATA[Produits phares sur la page d&#039;accueil]]></displayName>
<version><![CDATA[1.0]]></version>
<description><![CDATA[Affiche les produits phares au centre de votre page d&#039;accueil]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable>

View File

@@ -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 = '<h2>'.$this->displayName.'</h2>';
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');
}
}

View File

@@ -0,0 +1,9 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_0($object)
{
return ($object->registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
}