[*] FO : added smarty cache on blockbestsellers
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<module>
|
||||
<name>blockbestsellers</name>
|
||||
<displayName><![CDATA[Top-seller block]]></displayName>
|
||||
<version><![CDATA[1.1]]></version>
|
||||
<version><![CDATA[1.2]]></version>
|
||||
<description><![CDATA[Add a block displaying your store's top-selling products.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[front_office_features]]></tab>
|
||||
|
||||
9
modules/blockbestsellers/upgrade/install-1.2.php
Normal file
9
modules/blockbestsellers/upgrade/install-1.2.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
function upgrade_module_1_2($object)
|
||||
{
|
||||
return ($object->registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct') && $object->registerHook('actionOrderStatusPostUpdate'));
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user