From f78f3dc3a86c07c267f8c50131582ec433fb409a Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 3 Jul 2013 15:30:17 +0200 Subject: [PATCH 1/6] [*] FO : added smarty cache on crossselling module --- modules/crossselling/config.xml | 2 +- modules/crossselling/crossselling.php | 213 ++++++++++--------- modules/crossselling/upgrade/install-0.7.php | 9 + 3 files changed, 122 insertions(+), 102 deletions(-) create mode 100644 modules/crossselling/upgrade/install-0.7.php diff --git a/modules/crossselling/config.xml b/modules/crossselling/config.xml index 73592a426..59e2ea5ab 100755 --- a/modules/crossselling/config.xml +++ b/modules/crossselling/config.xml @@ -2,7 +2,7 @@ crossselling - + diff --git a/modules/crossselling/crossselling.php b/modules/crossselling/crossselling.php index 5bf4f95d6..99c7ae92c 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; @@ -126,66 +126,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 +196,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'); +} From d2440df8ca6b00a68695a130c201e49a8d8a0e4d Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 3 Jul 2013 15:49:32 +0200 Subject: [PATCH 2/6] [*] FO : added smarty cache on productscategory --- modules/crossselling/config.xml | 20 +-- modules/crossselling/crossselling.php | 1 + modules/productscategory/config.xml | 20 +-- modules/productscategory/productscategory.php | 162 ++++++++++-------- .../productscategory/upgrade/install-1.4.php | 9 + 5 files changed, 124 insertions(+), 88 deletions(-) create mode 100644 modules/productscategory/upgrade/install-1.4.php diff --git a/modules/crossselling/config.xml b/modules/crossselling/config.xml index 59e2ea5ab..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 99c7ae92c..31262888d 100755 --- a/modules/crossselling/crossselling.php +++ b/modules/crossselling/crossselling.php @@ -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')); } } 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')); +} From ec981b7f86b9eba74282c3d4d6dde6fc72abca53 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 3 Jul 2013 17:03:33 +0200 Subject: [PATCH 3/6] [*] WS : improved performances --- .../webservice/WebserviceOutputBuilder.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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']; From ae03669541051dc8f03291619f22ab4a12867bd3 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 3 Jul 2013 17:50:24 +0200 Subject: [PATCH 4/6] // Added the possibility to sort the modules in the tabs --- classes/Tab.php | 7 +++---- classes/controller/AdminController.php | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) 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..bc5b6bfab 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -2233,7 +2233,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) @@ -2252,6 +2252,7 @@ class AdminControllerCore extends Controller $this->modules_list[] = $module; } } + if (count($this->modules_list)) return true; From 47d343df90ee72d0dcaf1ba8abfb8cd282387040 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Thu, 4 Jul 2013 09:33:43 +0200 Subject: [PATCH 5/6] // Fixed module positions in tabs --- classes/controller/AdminController.php | 4 ++-- classes/helper/Helper.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index bc5b6bfab..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(); @@ -2249,9 +2248,10 @@ 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); From fd14268da3bebe45c897d0791042d7c20c6806ba Mon Sep 17 00:00:00 2001 From: gRoussac Date: Thu, 4 Jul 2013 15:23:39 +0200 Subject: [PATCH 6/6] // remove .gitattributes --- .gitattributes | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 176a458f9..000000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto