[*] FO : added smarty cache on blockbestsellers
This commit is contained in:
@@ -36,7 +36,7 @@ class BlockBestSellers extends Module
|
|||||||
{
|
{
|
||||||
$this->name = 'blockbestsellers';
|
$this->name = 'blockbestsellers';
|
||||||
$this->tab = 'front_office_features';
|
$this->tab = 'front_office_features';
|
||||||
$this->version = '1.1';
|
$this->version = '1.2';
|
||||||
$this->author = 'PrestaShop';
|
$this->author = 'PrestaShop';
|
||||||
$this->need_instance = 0;
|
$this->need_instance = 0;
|
||||||
|
|
||||||
@@ -51,14 +51,53 @@ class BlockBestSellers extends Module
|
|||||||
*/
|
*/
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
if (!parent::install() ||
|
$this->_clearCache('blockbestsellers.tpl');
|
||||||
!$this->registerHook('rightColumn') ||
|
$this->_clearCache('blockbestsellers-home.tpl');
|
||||||
!$this->registerHook('header') ||
|
|
||||||
!$this->registerHook('updateOrderStatus') ||
|
if (!parent::install()
|
||||||
!ProductSale::fillProductSales())
|
|| !$this->registerHook('rightColumn')
|
||||||
|
|| !$this->registerHook('header')
|
||||||
|
|| !$this->registerHook('actionOrderStatusPostUpdate')
|
||||||
|
|| !$this->registerHook('addproduct')
|
||||||
|
|| !$this->registerHook('updateproduct')
|
||||||
|
|| !$this->registerHook('deleteproduct')
|
||||||
|
|| !ProductSale::fillProductSales()
|
||||||
|
)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
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
|
* Called in administration -> module -> configure
|
||||||
@@ -102,28 +141,34 @@ class BlockBestSellers extends Module
|
|||||||
|
|
||||||
public function hookHome($params)
|
public function hookHome($params)
|
||||||
{
|
{
|
||||||
$best_sellers = $this->getBestSellers($params);
|
if (!$this->isCached('blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home')))
|
||||||
if ($best_sellers === false)
|
{
|
||||||
return;
|
$best_sellers = $this->getBestSellers($params);
|
||||||
|
if ($best_sellers === false)
|
||||||
|
return;
|
||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'best_sellers' => $best_sellers,
|
'best_sellers' => $best_sellers,
|
||||||
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
|
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
|
||||||
return $this->display(__FILE__, 'blockbestsellers-home.tpl');
|
}
|
||||||
|
return $this->display(__FILE__, 'blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookRightColumn($params)
|
public function hookRightColumn($params)
|
||||||
{
|
{
|
||||||
$best_sellers = $this->getBestSellers($params);
|
if (!$this->isCached('blockbestsellers.tpl', $this->getCacheId('blockbestsellers')))
|
||||||
if ($best_sellers === false)
|
{
|
||||||
return;
|
$best_sellers = $this->getBestSellers($params);
|
||||||
|
if ($best_sellers === false)
|
||||||
|
return;
|
||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'best_sellers' => $best_sellers,
|
'best_sellers' => $best_sellers,
|
||||||
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
|
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
|
||||||
'smallSize' => Image::getSize(ImageType::getFormatedName('small'))
|
'smallSize' => Image::getSize(ImageType::getFormatedName('small'))
|
||||||
));
|
));
|
||||||
return $this->display(__FILE__, 'blockbestsellers.tpl');
|
}
|
||||||
|
return $this->display(__FILE__, 'blockbestsellers.tpl', $this->getCacheId('blockbestsellers'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookLeftColumn($params)
|
public function hookLeftColumn($params)
|
||||||
@@ -136,7 +181,7 @@ class BlockBestSellers extends Module
|
|||||||
if (Configuration::get('PS_CATALOG_MODE'))
|
if (Configuration::get('PS_CATALOG_MODE'))
|
||||||
return false;
|
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);
|
return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false);
|
||||||
|
|
||||||
$bestsellers = array();
|
$bestsellers = array();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<module>
|
<module>
|
||||||
<name>blockbestsellers</name>
|
<name>blockbestsellers</name>
|
||||||
<displayName><![CDATA[Top-seller block]]></displayName>
|
<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>
|
<description><![CDATA[Add a block displaying your store's top-selling products.]]></description>
|
||||||
<author><![CDATA[PrestaShop]]></author>
|
<author><![CDATA[PrestaShop]]></author>
|
||||||
<tab><![CDATA[front_office_features]]></tab>
|
<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()
|
function install()
|
||||||
{
|
{
|
||||||
$this->_clearCache('homefeatured.tpl');
|
$this->_clearCache('homefeatured.tpl');
|
||||||
if (!Configuration::updateValue('HOME_FEATURED_NBR', 8)
|
Configuration::updateValue('HOME_FEATURED_NBR', 8);
|
||||||
|| !parent::install()
|
|
||||||
|
if (!parent::install()
|
||||||
|| !$this->registerHook('displayHome')
|
|| !$this->registerHook('displayHome')
|
||||||
|| !$this->registerHook('header')
|
|| !$this->registerHook('header')
|
||||||
|| !$this->registerHook('addproduct')
|
|| !$this->registerHook('addproduct')
|
||||||
@@ -117,7 +118,6 @@ class HomeFeatured extends Module
|
|||||||
{
|
{
|
||||||
if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured')))
|
if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured')))
|
||||||
{
|
{
|
||||||
p('no cache');
|
|
||||||
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
|
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
|
||||||
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
|
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
|
||||||
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));
|
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));
|
||||||
|
|||||||
Reference in New Issue
Block a user