diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 176a458f9..000000000
--- a/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-* text=auto
diff --git a/classes/Tab.php b/classes/Tab.php
index 542d68c7f..5a0b211d8 100644
--- a/classes/Tab.php
+++ b/classes/Tab.php
@@ -538,11 +538,10 @@ class TabCore extends ObjectModel
foreach($tab->attributes() as $key => $value)
if ($key == 'display_type')
$display_type = (string)$value;
-
+
foreach ($tab->children() as $module)
- foreach ($module->attributes() as $k => $v)
- if ($k == 'name')
- $modules_list[$display_type][] = (string)$v;
+ $modules_list[$display_type][(int)$module['position']] = (string)$module['name'];
+ ksort($modules_list[$display_type]);
}
}
diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php
index 597e75371..f63f329cf 100644
--- a/classes/controller/AdminController.php
+++ b/classes/controller/AdminController.php
@@ -1534,7 +1534,6 @@ class AdminControllerCore extends Controller
public function renderModulesList()
{
-
if ($this->getModulesList($this->filter_modules_list))
{
$helper = new Helper();
@@ -2233,7 +2232,7 @@ class AdminControllerCore extends Controller
$all_modules = Module::getModulesOnDisk(true);
$this->modules_list = array();
- foreach($all_modules as $module)
+ foreach ($all_modules as $module)
{
$perm = true;
if ($module->id)
@@ -2249,9 +2248,11 @@ class AdminControllerCore extends Controller
if (in_array($module->name, $filter_modules_list) && $perm)
{
$this->fillModuleData($module, 'select');
- $this->modules_list[] = $module;
+ $this->modules_list[array_search($module->name, $filter_modules_list)] = $module;
}
}
+ ksort($this->modules_list);
+
if (count($this->modules_list))
return true;
diff --git a/classes/helper/Helper.php b/classes/helper/Helper.php
index d5516c3e6..826502bc0 100755
--- a/classes/helper/Helper.php
+++ b/classes/helper/Helper.php
@@ -351,7 +351,6 @@ class HelperCore
public function renderModulesList($modules_list)
{
$this->tpl_vars = array('modules_list' => $modules_list);
-
$tpl = $this->createTemplate('helpers/modules_list/list.tpl');
$tpl->assign($this->tpl_vars);
diff --git a/classes/webservice/WebserviceOutputBuilder.php b/classes/webservice/WebserviceOutputBuilder.php
index 5fb9cb7c9..cfe632530 100755
--- a/classes/webservice/WebserviceOutputBuilder.php
+++ b/classes/webservice/WebserviceOutputBuilder.php
@@ -47,6 +47,8 @@ class WebserviceOutputBuilderCore
protected $virtualFields = array();
protected $statusInt;
protected $wsParamOverrides;
+
+ protected static $_cache_ws_parameters = array();
// Header properties
protected $headerParams = array(
@@ -359,7 +361,11 @@ class WebserviceOutputBuilderCore
$type_of_view = self::VIEW_DETAILS;
}
- $ws_params = $objects['empty']->getWebserviceParameters();
+ $class = get_class($objects['empty']);
+ if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
+ WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $objects['empty']->getWebserviceParameters();
+ $ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
+
foreach ($this->wsParamOverrides AS $p)
{
$object = $p['object'];
@@ -406,7 +412,11 @@ class WebserviceOutputBuilderCore
*/
public function renderEntityMinimum($object, $depth)
{
- $ws_params = $object->getWebserviceParameters();
+ $class = get_class($object);
+ if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
+ WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $object->getWebserviceParameters();
+ $ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
+
$more_attr['id'] = $object->id;
$more_attr['xlink_resource'] = $this->wsUrl.$ws_params['objectsNodeName'].'/'.$object->id;
$output = $this->setIndent($depth).$this->objectRender->renderNodeHeader($ws_params['objectNodeName'], $ws_params, $more_attr, false);
@@ -446,7 +456,12 @@ class WebserviceOutputBuilderCore
public function renderEntity($object, $depth)
{
$output = '';
- $ws_params = $object->getWebserviceParameters();
+
+ $class = get_class($object);
+ if (!isset(WebserviceOutputBuilder::$_cache_ws_parameters[$class]))
+ WebserviceOutputBuilder::$_cache_ws_parameters[$class] = $object->getWebserviceParameters();
+ $ws_params = WebserviceOutputBuilder::$_cache_ws_parameters[$class];
+
foreach ($this->wsParamOverrides AS $p)
{
$o = $p['object'];
diff --git a/modules/crossselling/config.xml b/modules/crossselling/config.xml
index 73592a426..8aed65a6b 100755
--- a/modules/crossselling/config.xml
+++ b/modules/crossselling/config.xml
@@ -1,12 +1,12 @@
-
- crossselling
-
-
-
-
-
- 1
- 0
+
+ crossselling
+
+
+
+
+
+ 1
+ 0
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/modules/crossselling/crossselling.php b/modules/crossselling/crossselling.php
index 5bf4f95d6..31262888d 100755
--- a/modules/crossselling/crossselling.php
+++ b/modules/crossselling/crossselling.php
@@ -35,7 +35,7 @@ class CrossSelling extends Module
{
$this->name = 'crossselling';
$this->tab = 'front_office_features';
- $this->version = 0.1;
+ $this->version = 0.7;
$this->author = 'PrestaShop';
$this->need_instance = 0;
@@ -54,18 +54,18 @@ class CrossSelling extends Module
!$this->registerHook('productFooter') OR
!$this->registerHook('header') OR
!$this->registerHook('shoppingCart') OR
+ !$this->registerHook('actionOrderStatusPostUpdate') OR
!Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', 0) OR
!Configuration::updateValue('CROSSSELLING_NBR', 10))
return false;
+ $this->_clearCache('crossselling.tpl');
return true;
}
public function uninstall()
{
+ $this->_clearCache('crossselling.tpl');
if (!parent::uninstall() OR
- !$this->unregisterHook('productFooter') OR
- !$this->unregisterHook('header') OR
- !$this->unregisterHook('shoppingCart') OR
!Configuration::deleteByName('CROSSSELLING_DISPLAY_PRICE') OR
!Configuration::deleteByName('CROSSSELLING_NBR'))
return false;
@@ -88,6 +88,7 @@ class CrossSelling extends Module
{
Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice'));
Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr'));
+ $this->_clearCache('crossselling.tpl');
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
}
}
@@ -126,66 +127,69 @@ class CrossSelling extends Module
if (!$params['products'])
return;
- $qOrders = 'SELECT o.id_order
- FROM '._DB_PREFIX_.'orders o
- LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
- WHERE o.valid = 1 AND (';
- $nProducts = count($params['products']);
- $i = 1;
- $pIds = array();
- foreach ($params['products'] as $product)
+ $cache_id = 'crossselling|shoppingcart|'.(int)$params['products'];
+ if (!$this->isCached('crossselling.tpl', $this->getCacheId($cache_id)))
{
- $qOrders .= 'od.product_id = '.(int)$product['id_product'];
- if ($i < $nProducts)
- $qOrders .= ' OR ';
- ++$i;
- $pIds[] = (int)$product['id_product'];
- }
- $qOrders .= ')';
- $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($qOrders);
-
- if (sizeof($orders))
- {
-
- $list = '';
- foreach ($orders AS $order)
- $list .= (int)$order['id_order'].',';
- $list = rtrim($list, ',');
-
- $list_product_ids = join(',', $pIds);
- $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
- FROM '._DB_PREFIX_.'order_detail od
- LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
- '.Shop::addSqlAssociation('product', 'p').'
- LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
- LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
- LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
- WHERE od.id_order IN ('.$list.')
- AND pl.id_lang = '.(int)$this->context->language->id.'
- AND cl.id_lang = '.(int)$this->context->language->id.'
- AND od.product_id NOT IN ('.$list_product_ids.')
- AND i.cover = 1
- AND product_shop.active = 1
- ORDER BY RAND()
- LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
- ');
-
- $taxCalc = Product::getTaxCalculationMethod();
- foreach ($orderProducts AS &$orderProduct)
+ $qOrders = 'SELECT o.id_order
+ FROM '._DB_PREFIX_.'orders o
+ LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
+ WHERE o.valid = 1 AND (';
+ $nProducts = count($params['products']);
+ $i = 1;
+ $pIds = array();
+ foreach ($params['products'] as $product)
{
- $orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
- $orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
- if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
- $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
- elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
- $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
+ $qOrders .= 'od.product_id = '.(int)$product['id_product'];
+ if ($i < $nProducts)
+ $qOrders .= ' OR ';
+ ++$i;
+ $pIds[] = (int)$product['id_product'];
}
+ $qOrders .= ')';
+ $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($qOrders);
- $this->smarty->assign(array('order' => (count($pIds) > 1 ? true : false), 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
- 'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
+ if (sizeof($orders))
+ {
+ $list = '';
+ foreach ($orders AS $order)
+ $list .= (int)$order['id_order'].',';
+ $list = rtrim($list, ',');
+
+ $list_product_ids = join(',', $pIds);
+ $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+ SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
+ FROM '._DB_PREFIX_.'order_detail od
+ LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
+ '.Shop::addSqlAssociation('product', 'p').'
+ LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
+ LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
+ LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
+ WHERE od.id_order IN ('.$list.')
+ AND pl.id_lang = '.(int)$this->context->language->id.'
+ AND cl.id_lang = '.(int)$this->context->language->id.'
+ AND od.product_id NOT IN ('.$list_product_ids.')
+ AND i.cover = 1
+ AND product_shop.active = 1
+ ORDER BY RAND()
+ LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
+ ');
+
+ $taxCalc = Product::getTaxCalculationMethod();
+ foreach ($orderProducts AS &$orderProduct)
+ {
+ $orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
+ $orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
+ if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
+ $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
+ elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
+ $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
+ }
+
+ $this->smarty->assign(array('order' => (count($pIds) > 1 ? true : false), 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
+ 'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
+ }
}
- return $this->display(__FILE__, 'crossselling.tpl');
+ return $this->display(__FILE__, 'crossselling.tpl', $this->getCacheId($cache_id));
}
/**
@@ -193,52 +197,60 @@ class CrossSelling extends Module
*/
public function hookProductFooter($params)
{
-
- $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT o.id_order
- FROM '._DB_PREFIX_.'orders o
- LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
- WHERE o.valid = 1 AND od.product_id = '.(int)$params['product']->id);
-
- if (sizeof($orders))
+ $cache_id = 'crossselling|productfooter|'.(int)$params['product']->id;
+ if (!$this->isCached('crossselling.tpl', $this->getCacheId($cache_id)))
{
- $list = '';
- foreach ($orders AS $order)
- $list .= (int)$order['id_order'].',';
- $list = rtrim($list, ',');
+ $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+ SELECT o.id_order
+ FROM '._DB_PREFIX_.'orders o
+ LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
+ WHERE o.valid = 1 AND od.product_id = '.(int)$params['product']->id);
- $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
- FROM '._DB_PREFIX_.'order_detail od
- LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
- '.Shop::addSqlAssociation('product', 'p').'
- LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
- LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
- LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
- WHERE od.id_order IN ('.$list.')
- AND pl.id_lang = '.(int)$this->context->language->id.'
- AND cl.id_lang = '.(int)$this->context->language->id.'
- AND od.product_id != '.(int)$params['product']->id.'
- AND i.cover = 1
- AND product_shop.active = 1
- ORDER BY RAND()
- LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
- ');
-
- $taxCalc = Product::getTaxCalculationMethod();
- foreach ($orderProducts AS &$orderProduct)
+ if (sizeof($orders))
{
- $orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
- $orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
- if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
- $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
- elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
- $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
- }
+ $list = '';
+ foreach ($orders AS $order)
+ $list .= (int)$order['id_order'].',';
+ $list = rtrim($list, ',');
- $this->smarty->assign(array('order' => false, 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
- 'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
+ $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
+ SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
+ FROM '._DB_PREFIX_.'order_detail od
+ LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
+ '.Shop::addSqlAssociation('product', 'p').'
+ LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
+ LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
+ LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
+ WHERE od.id_order IN ('.$list.')
+ AND pl.id_lang = '.(int)$this->context->language->id.'
+ AND cl.id_lang = '.(int)$this->context->language->id.'
+ AND od.product_id != '.(int)$params['product']->id.'
+ AND i.cover = 1
+ AND product_shop.active = 1
+ ORDER BY RAND()
+ LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
+ ');
+
+ $taxCalc = Product::getTaxCalculationMethod();
+ foreach ($orderProducts AS &$orderProduct)
+ {
+ $orderProduct['image'] = $this->context->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
+ $orderProduct['link'] = $this->context->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
+ if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2))
+ $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
+ elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1)
+ $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
+ }
+
+ $this->smarty->assign(array('order' => false, 'orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0),
+ 'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')));
+ }
}
- return $this->display(__FILE__, 'crossselling.tpl');
+ return $this->display(__FILE__, 'crossselling.tpl', $this->getCacheId($cache_id));
+ }
+
+ public function hookActionOrderStatusPostUpdate($params)
+ {
+ $this->_clearCache('crossselling.tpl');
}
}
diff --git a/modules/crossselling/upgrade/install-0.7.php b/modules/crossselling/upgrade/install-0.7.php
new file mode 100644
index 000000000..4568a848e
--- /dev/null
+++ b/modules/crossselling/upgrade/install-0.7.php
@@ -0,0 +1,9 @@
+registerHook('actionOrderStatusPostUpdate');
+}
diff --git a/modules/productscategory/config.xml b/modules/productscategory/config.xml
index af48bb894..4b8faeec9 100755
--- a/modules/productscategory/config.xml
+++ b/modules/productscategory/config.xml
@@ -1,12 +1,12 @@
-
- productscategory
-
-
-
-
-
- 1
- 0
+
+ productscategory
+
+
+
+
+
+ 1
+ 0
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/modules/productscategory/productscategory.php b/modules/productscategory/productscategory.php
index 00d394e0c..fb1f74e36 100644
--- a/modules/productscategory/productscategory.php
+++ b/modules/productscategory/productscategory.php
@@ -34,7 +34,7 @@ class productsCategory extends Module
public function __construct()
{
$this->name = 'productscategory';
- $this->version = '1.3';
+ $this->version = '1.4';
$this->author = 'PrestaShop';
$this->tab = 'front_office_features';
$this->need_instance = 0;
@@ -50,16 +50,22 @@ class productsCategory extends Module
public function install()
{
- if (!parent::install() OR !$this->registerHook('productfooter') OR !$this->registerHook('header') OR !Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0))
- return false;
- return true;
+ Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0);
+ $this->_clearCache('productscategory.tpl');
+ return (parent::install()
+ && $this->registerHook('productfooter')
+ && $this->registerHook('header')
+ && $this->registerHook('addproduct')
+ && $this->registerHook('updateproduct')
+ && $this->registerHook('deleteproduct')
+ );
}
public function uninstall()
{
- if (!parent::uninstall() OR !Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE'))
- return false;
- return true;
+ Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE');
+ $this->_clearCache('productscategory.tpl');
+ return parent::uninstall();
}
public function getContent()
@@ -70,6 +76,7 @@ class productsCategory extends Module
elseif (Tools::isSubmit('submitCross'))
{
Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
+ $this->_clearCache('productscategory.tpl');
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
}
$this->_html .= '
@@ -100,75 +107,79 @@ class productsCategory extends Module
public function hookProductFooter($params)
{
- $idProduct = (int)(Tools::getValue('id_product'));
- $product = new Product((int)($idProduct));
-
- /* 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));
- }
+ $id_product = (int)$params['product']->id;
+ $product = $params['product'];
- if (!Validate::isLoadedObject($category) OR !$category->active)
- return;
+ $cache_id = 'productscategory|'.$id_product.'|'.(isset($params['category']->id_category) ? (int)$params['category']->id_category : $product->id_category_default);
- // Get infos
- $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))
+ if (!$this->isCached('productscategory.tpl', $this->getCacheId($cache_id)))
{
- foreach ($categoryProducts AS $key => $categoryProduct)
- if ($categoryProduct['id_product'] == $idProduct)
- {
- unset($categoryProducts[$key]);
- break;
- }
+ /* 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)
+ return;
- $taxes = Product::getTaxCalculationMethod();
- if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
+ // Get infos
+ $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 ($categoryProduct['id_product'] != $idProduct)
+ 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);
+ unset($categoryProducts[$key]);
+ break;
}
-
- // 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)
@@ -177,4 +188,19 @@ class productsCategory extends Module
$this->context->controller->addJS($this->_path.'productscategory.js');
$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');
+ }
}
diff --git a/modules/productscategory/upgrade/install-1.4.php b/modules/productscategory/upgrade/install-1.4.php
new file mode 100644
index 000000000..f20e47235
--- /dev/null
+++ b/modules/productscategory/upgrade/install-1.4.php
@@ -0,0 +1,9 @@
+registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct'));
+}