From eb40f7db24bf408291fdbb38f455b3681a17cc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Mon, 30 Sep 2013 18:48:59 +0200 Subject: [PATCH] // Improve cache colors list --- controllers/front/CategoryController.php | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 9957da6e9..f75765774 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -204,38 +204,40 @@ class CategoryControllerCore extends FrontController { if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) $product['minimal_quantity'] = $product['product_attribute_minimal_quantity']; - if (!$this->isCached(_PS_THEME_DIR_.'product-list-colors.tpl', 'productlist_colors|'.$product['id_product'])) - $products_need_cache[] = (int)$product['id_product']; + + if (!$this->isCached(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product']))) + $products_need_cache[] = (int)$product['id_product']; } unset($product); - - $colors = array(); + + $colors = false; if (count($products_need_cache)) $colors = Product::getAttributesColorList($products_need_cache); - if (count($colors)) + Tools::enableCache(); + foreach ($this->cat_products as &$product) { - Tools::enableCache(); - - foreach ($this->cat_products as &$product) - if (isset($colors[$product['id_product']]) && count($colors[$product['id_product']])) - { - $data = $this->context->smarty->createData(); - $data->assign(array( + $tpl = $this->context->smarty->createTemplate(_PS_THEME_DIR_.'product-list-colors.tpl'); + if (isset($colors[$product['id_product']])) + $tpl->assign(array( 'id_product' => $product['id_product'], 'colors_list' => $colors[$product['id_product']] )); - $product['color_list'] = $this->context->smarty->createTemplate(_PS_THEME_DIR_.'product-list-colors.tpl', $data)->fetch(_PS_THEME_DIR_.'product-list-colors.tpl', 'productlist_colors|'.(int)$product['id_product']); - } - else - $product['color_list'] = ''; - - Tools::restoreCacheSettings(); + if (!in_array($product['id_product'], $products_need_cache) || isset($colors[$product['id_product']])) + $product['color_list'] = $tpl->fetch(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product'])); + else + $product['color_list'] = ''; } + Tools::restoreCacheSettings(); $this->context->smarty->assign('nb_products', $this->nbProducts); } + protected function getColorsListCacheId($id_product) + { + return 'productlist_colors|'.(int)$id_product.'|'.$this->context->shop->id; + } + /** * Get instance of current category */