[*] FO : added smarty cache on productscategory
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<module>
|
<module>
|
||||||
<name>crossselling</name>
|
<name>crossselling</name>
|
||||||
<displayName><![CDATA[Cross Selling]]></displayName>
|
<displayName><![CDATA[Cross Selling]]></displayName>
|
||||||
<version><![CDATA[0.7]]></version>
|
<version><![CDATA[0.7]]></version>
|
||||||
<description><![CDATA[Customers who bought this product also bought:]]></description>
|
<description><![CDATA[Customers who bought this product also bought:]]></description>
|
||||||
<author><![CDATA[PrestaShop]]></author>
|
<author><![CDATA[PrestaShop]]></author>
|
||||||
<tab><![CDATA[front_office_features]]></tab>
|
<tab><![CDATA[front_office_features]]></tab>
|
||||||
<is_configurable>1</is_configurable>
|
<is_configurable>1</is_configurable>
|
||||||
<need_instance>0</need_instance>
|
<need_instance>0</need_instance>
|
||||||
<limited_countries></limited_countries>
|
<limited_countries></limited_countries>
|
||||||
</module>
|
</module>
|
||||||
@@ -88,6 +88,7 @@ class CrossSelling extends Module
|
|||||||
{
|
{
|
||||||
Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice'));
|
Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice'));
|
||||||
Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr'));
|
Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr'));
|
||||||
|
$this->_clearCache('crossselling.tpl');
|
||||||
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
|
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<module>
|
<module>
|
||||||
<name>productscategory</name>
|
<name>productscategory</name>
|
||||||
<displayName><![CDATA[Products Category]]></displayName>
|
<displayName><![CDATA[Products Category]]></displayName>
|
||||||
<version><![CDATA[1.3]]></version>
|
<version><![CDATA[1.4]]></version>
|
||||||
<description><![CDATA[Display products of the same category on the product page.]]></description>
|
<description><![CDATA[Display products of the same category on the product page.]]></description>
|
||||||
<author><![CDATA[PrestaShop]]></author>
|
<author><![CDATA[PrestaShop]]></author>
|
||||||
<tab><![CDATA[front_office_features]]></tab>
|
<tab><![CDATA[front_office_features]]></tab>
|
||||||
<is_configurable>1</is_configurable>
|
<is_configurable>1</is_configurable>
|
||||||
<need_instance>0</need_instance>
|
<need_instance>0</need_instance>
|
||||||
<limited_countries></limited_countries>
|
<limited_countries></limited_countries>
|
||||||
</module>
|
</module>
|
||||||
@@ -34,7 +34,7 @@ class productsCategory extends Module
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->name = 'productscategory';
|
$this->name = 'productscategory';
|
||||||
$this->version = '1.3';
|
$this->version = '1.4';
|
||||||
$this->author = 'PrestaShop';
|
$this->author = 'PrestaShop';
|
||||||
$this->tab = 'front_office_features';
|
$this->tab = 'front_office_features';
|
||||||
$this->need_instance = 0;
|
$this->need_instance = 0;
|
||||||
@@ -50,16 +50,22 @@ class productsCategory extends Module
|
|||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
if (!parent::install() OR !$this->registerHook('productfooter') OR !$this->registerHook('header') OR !Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0))
|
Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0);
|
||||||
return false;
|
$this->_clearCache('productscategory.tpl');
|
||||||
return true;
|
return (parent::install()
|
||||||
|
&& $this->registerHook('productfooter')
|
||||||
|
&& $this->registerHook('header')
|
||||||
|
&& $this->registerHook('addproduct')
|
||||||
|
&& $this->registerHook('updateproduct')
|
||||||
|
&& $this->registerHook('deleteproduct')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
{
|
{
|
||||||
if (!parent::uninstall() OR !Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE'))
|
Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE');
|
||||||
return false;
|
$this->_clearCache('productscategory.tpl');
|
||||||
return true;
|
return parent::uninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent()
|
public function getContent()
|
||||||
@@ -70,6 +76,7 @@ class productsCategory extends Module
|
|||||||
elseif (Tools::isSubmit('submitCross'))
|
elseif (Tools::isSubmit('submitCross'))
|
||||||
{
|
{
|
||||||
Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
|
Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
|
||||||
|
$this->_clearCache('productscategory.tpl');
|
||||||
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
|
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
|
||||||
}
|
}
|
||||||
$this->_html .= '
|
$this->_html .= '
|
||||||
@@ -100,75 +107,79 @@ class productsCategory extends Module
|
|||||||
|
|
||||||
public function hookProductFooter($params)
|
public function hookProductFooter($params)
|
||||||
{
|
{
|
||||||
$idProduct = (int)(Tools::getValue('id_product'));
|
$id_product = (int)$params['product']->id;
|
||||||
$product = new Product((int)($idProduct));
|
$product = $params['product'];
|
||||||
|
|
||||||
/* If the visitor has came to this product by a category, use this one */
|
|
||||||
if (isset($params['category']->id_category))
|
|
||||||
$category = $params['category'];
|
|
||||||
/* Else, use the default product category */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isset($product->id_category_default) AND $product->id_category_default > 1)
|
|
||||||
$category = New Category((int)($product->id_category_default));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Validate::isLoadedObject($category) OR !$category->active)
|
$cache_id = 'productscategory|'.$id_product.'|'.(isset($params['category']->id_category) ? (int)$params['category']->id_category : $product->id_category_default);
|
||||||
return;
|
|
||||||
|
|
||||||
// Get infos
|
if (!$this->isCached('productscategory.tpl', $this->getCacheId($cache_id)))
|
||||||
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
|
|
||||||
$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
|
|
||||||
$middlePosition = 0;
|
|
||||||
|
|
||||||
// Remove current product from the list
|
|
||||||
if (is_array($categoryProducts) AND sizeof($categoryProducts))
|
|
||||||
{
|
{
|
||||||
foreach ($categoryProducts AS $key => $categoryProduct)
|
/* If the visitor has came to this product by a category, use this one */
|
||||||
if ($categoryProduct['id_product'] == $idProduct)
|
if (isset($params['category']->id_category))
|
||||||
{
|
$category = $params['category'];
|
||||||
unset($categoryProducts[$key]);
|
/* Else, use the default product category */
|
||||||
break;
|
else
|
||||||
}
|
{
|
||||||
|
if (isset($product->id_category_default) AND $product->id_category_default > 1)
|
||||||
|
$category = new Category((int)$product->id_category_default);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Validate::isLoadedObject($category) OR !$category->active)
|
||||||
|
return;
|
||||||
|
|
||||||
$taxes = Product::getTaxCalculationMethod();
|
// Get infos
|
||||||
if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
|
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
|
||||||
|
$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
|
||||||
|
$middlePosition = 0;
|
||||||
|
|
||||||
|
// Remove current product from the list
|
||||||
|
if (is_array($categoryProducts) AND sizeof($categoryProducts))
|
||||||
|
{
|
||||||
foreach ($categoryProducts AS $key => $categoryProduct)
|
foreach ($categoryProducts AS $key => $categoryProduct)
|
||||||
if ($categoryProduct['id_product'] != $idProduct)
|
if ($categoryProduct['id_product'] == $id_product)
|
||||||
{
|
{
|
||||||
if ($taxes == 0 OR $taxes == 2)
|
unset($categoryProducts[$key]);
|
||||||
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2);
|
break;
|
||||||
elseif ($taxes == 1)
|
|
||||||
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get positions
|
|
||||||
$middlePosition = round($sizeOfCategoryProducts / 2, 0);
|
|
||||||
$productPosition = $this->getCurrentProduct($categoryProducts, (int)$idProduct);
|
|
||||||
|
|
||||||
// Flip middle product with current product
|
|
||||||
if ($productPosition)
|
|
||||||
{
|
|
||||||
$tmp = $categoryProducts[$middlePosition-1];
|
|
||||||
$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
|
|
||||||
$categoryProducts[$productPosition] = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If products tab higher than 30, slice it
|
|
||||||
if ($sizeOfCategoryProducts > 30)
|
|
||||||
{
|
|
||||||
$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
|
|
||||||
$middlePosition = 15;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display tpl
|
|
||||||
$this->smarty->assign(array(
|
|
||||||
'categoryProducts' => $categoryProducts,
|
|
||||||
'middlePosition' => (int)$middlePosition,
|
|
||||||
'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
|
|
||||||
|
|
||||||
return $this->display(__FILE__, 'productscategory.tpl');
|
$taxes = Product::getTaxCalculationMethod();
|
||||||
|
if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
|
||||||
|
foreach ($categoryProducts AS $key => $categoryProduct)
|
||||||
|
if ($categoryProduct['id_product'] != $id_product)
|
||||||
|
{
|
||||||
|
if ($taxes == 0 OR $taxes == 2)
|
||||||
|
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2);
|
||||||
|
elseif ($taxes == 1)
|
||||||
|
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get positions
|
||||||
|
$middlePosition = round($sizeOfCategoryProducts / 2, 0);
|
||||||
|
$productPosition = $this->getCurrentProduct($categoryProducts, (int)$id_product);
|
||||||
|
|
||||||
|
// Flip middle product with current product
|
||||||
|
if ($productPosition)
|
||||||
|
{
|
||||||
|
$tmp = $categoryProducts[$middlePosition-1];
|
||||||
|
$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
|
||||||
|
$categoryProducts[$productPosition] = $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If products tab higher than 30, slice it
|
||||||
|
if ($sizeOfCategoryProducts > 30)
|
||||||
|
{
|
||||||
|
$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
|
||||||
|
$middlePosition = 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display tpl
|
||||||
|
$this->smarty->assign(array(
|
||||||
|
'categoryProducts' => $categoryProducts,
|
||||||
|
'middlePosition' => (int)$middlePosition,
|
||||||
|
'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
|
||||||
|
}
|
||||||
|
return $this->display(__FILE__, 'productscategory.tpl', $this->getCacheId($cache_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookHeader($params)
|
public function hookHeader($params)
|
||||||
@@ -177,4 +188,19 @@ class productsCategory extends Module
|
|||||||
$this->context->controller->addJS($this->_path.'productscategory.js');
|
$this->context->controller->addJS($this->_path.'productscategory.js');
|
||||||
$this->context->controller->addJqueryPlugin('serialScroll');
|
$this->context->controller->addJqueryPlugin('serialScroll');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hookAddProduct($params)
|
||||||
|
{
|
||||||
|
$this->_clearCache('productscategory.tpl');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hookUpdateProduct($params)
|
||||||
|
{
|
||||||
|
$this->_clearCache('productscategory.tpl');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hookDeleteProduct($params)
|
||||||
|
{
|
||||||
|
$this->_clearCache('productscategory.tpl');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('_PS_VERSION_'))
|
||||||
|
exit;
|
||||||
|
|
||||||
|
function upgrade_module_1_4($object)
|
||||||
|
{
|
||||||
|
return ($object->registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user