[*] MO: Add smarty cache on blocksupplier and blockmanufacturer

This commit is contained in:
Rémi Gaillard
2013-05-22 15:46:30 +02:00
parent 487c567224
commit de945adf79
3 changed files with 72 additions and 25 deletions
+7 -1
View File
@@ -7,4 +7,10 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL
ALTER TABLE `PREFIX_webservice_account` CHANGE `class_name` `class_name` VARCHAR(64) NOT NULL DEFAULT 'WebserviceRequest',
CHANGE `module_name` `module_name` VARCHAR(64) NULL DEFAULT NULL;
/* PHP:add_module_to_hook(blockcart, actionCartListOverride); */;
/* PHP:add_module_to_hook(blockcart, actionCartListOverride); */;
/* PHP:add_module_to_hook(blockmanufacturer, actionObjectManufacturerDeleteAfter); */;
/* PHP:add_module_to_hook(blockmanufacturer, actionObjectManufacturerAddAfter); */;
/* PHP:add_module_to_hook(blockmanufacturer, actionObjectManufacturerUpdateAfter); */;
/* PHP:add_module_to_hook(blocksupplier, actionObjectSupplierDeleteAfter); */;
/* PHP:add_module_to_hook(blocksupplier, actionObjectSupplierAddAfter); */;
/* PHP:add_module_to_hook(blocksupplier, actionObjectSupplierUpdateAfter); */;
@@ -48,19 +48,25 @@ class BlockManufacturer extends Module
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', true);
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', 5);
Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', true);
return parent::install() && $this->registerHook('leftColumn') && $this->registerHook('header');
return parent::install() &&
$this->registerHook('leftColumn') &&
$this->registerHook('header') &&
$this->registerHook('actionObjectManufacturerDeleteAfter') &&
$this->registerHook('actionObjectManufacturerAddAfter') &&
$this->registerHook('actionObjectManufacturerUpdateAfter');
}
public function hookLeftColumn($params)
{
$this->smarty->assign(array(
'manufacturers' => Manufacturer::getManufacturers(),
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
'display_link_manufacturer' => Configuration::get('PS_DISPLAY_SUPPLIERS'),
));
return $this->display(__FILE__, 'blockmanufacturer.tpl');
if (!$this->isCached('blockmanufacturer.tpl', $this->getCacheId()))
$this->smarty->assign(array(
'manufacturers' => Manufacturer::getManufacturers(),
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
'display_link_manufacturer' => Configuration::get('PS_DISPLAY_SUPPLIERS'),
));
return $this->display(__FILE__, 'blockmanufacturer.tpl', $this->getCacheId());
}
public function hookRightColumn($params)
@@ -85,6 +91,7 @@ class BlockManufacturer extends Module
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', $text_list);
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', $text_nb);
Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', $form_list);
$this->_clearCache('blockmanufacturer.tpl');
}
if (isset($errors) && count($errors))
$output .= $this->displayError(implode('<br />', $errors));
@@ -126,4 +133,19 @@ class BlockManufacturer extends Module
{
$this->context->controller->addCSS(($this->_path).'blockmanufacturer.css', 'all');
}
public function hookActionObjectManufacturerUpdateAfter($params)
{
$this->_clearCache('blockmanufacturer.tpl');
}
public function hookActionObjectManufacturerAddAfter($params)
{
$this->_clearCache('blockmanufacturer.tpl');
}
public function hookActionObjectManufacturerDeleteAfter($params)
{
$this->_clearCache('blockmanufacturer.tpl');
}
}
+34 -15
View File
@@ -47,9 +47,12 @@ class BlockSupplier extends Module
{
if (!parent::install())
return false;
if (!$this->registerHook('displayLeftColumn'))
return false;
if (!$this->registerHook('displayHeader'))
if (!$this->registerHook('displayLeftColumn') ||
!$this->registerHook('displayHeader') ||
!$this->registerHook('actionObjectSupplierDeleteAfter') ||
!$this->registerHook('actionObjectSupplierAddAfter') ||
!$this->registerHook('actionObjectSupplierUpdateAfter')
)
return false;
Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', true);
Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', 5);
@@ -73,16 +76,16 @@ class BlockSupplier extends Module
function hookDisplayLeftColumn($params)
{
$id_lang = (int)Context::getContext()->language->id;
$this->smarty->assign(array(
'suppliers' => Supplier::getSuppliers(false, $id_lang),
'link' => $this->context->link,
'text_list' => Configuration::get('SUPPLIER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('SUPPLIER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('SUPPLIER_DISPLAY_FORM'),
'display_link_supplier' => Configuration::get('PS_DISPLAY_SUPPLIERS')
));
return $this->display(__FILE__, 'blocksupplier.tpl');
if (!$this->isCached('blocksupplier.tpl', $this->getCacheId()))
$this->smarty->assign(array(
'suppliers' => Supplier::getSuppliers(false, $id_lang),
'link' => $this->context->link,
'text_list' => Configuration::get('SUPPLIER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('SUPPLIER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('SUPPLIER_DISPLAY_FORM'),
'display_link_supplier' => Configuration::get('PS_DISPLAY_SUPPLIERS')
));
return $this->display(__FILE__, 'blocksupplier.tpl', $this->getCacheId());
}
function getContent()
@@ -102,6 +105,7 @@ class BlockSupplier extends Module
Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', $text_list);
Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', $text_nb);
Configuration::updateValue('SUPPLIER_DISPLAY_FORM', $form_list);
$this->_clearCache('blocksupplier.tpl');
}
if (isset($errors) AND sizeof($errors))
$output .= $this->displayError(implode('<br />', $errors));
@@ -139,14 +143,29 @@ class BlockSupplier extends Module
return $output;
}
function hookDisplayRightColumn($params)
public function hookDisplayRightColumn($params)
{
return $this->hookDisplayLeftColumn($params);
}
function hookDisplayHeader($params)
public function hookDisplayHeader($params)
{
$this->context->controller->addCSS(($this->_path).'blocksupplier.css', 'all');
}
public function hookActionObjectSupplierUpdateAfter($params)
{
$this->_clearCache('blocksupplier.tpl');
}
public function hookActionObjectSupplierAddAfter($params)
{
$this->_clearCache('blocksupplier.tpl');
}
public function hookActionObjectSupplierDeleteAfter($params)
{
$this->_clearCache('blocksupplier.tpl');
}
}