diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index d02f87448..bcf8a2af8 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -1142,4 +1142,40 @@ class FrontControllerCore extends Controller 'logo_url' => $logo ); } + + protected function addColorsToProductList(&$products) + { + if (!count($products)) + return; + + $products_need_cache = array(); + foreach ($products as &$product) + if (!$this->isCached(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product']))) + $products_need_cache[] = (int)$product['id_product']; + + $colors = false; + if (count($products_need_cache)) + $colors = Product::getAttributesColorList($products_need_cache); + + Tools::enableCache(); + foreach ($products as &$product) + { + $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']] + )); + 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(); + } + + protected function getColorsListCacheId($id_product) + { + return 'productlist_colors|'.(int)$id_product.'|'.$this->context->shop->id; + } } diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index f75765774..95e1efd6e 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -199,45 +199,16 @@ class CategoryControllerCore extends FrontController // Pagination must be call after "getProducts" $this->pagination($this->nbProducts); - $products_need_cache = array(); + foreach ($this->cat_products as &$product) - { 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', $this->getColorsListCacheId($product['id_product']))) - $products_need_cache[] = (int)$product['id_product']; - } - unset($product); - - $colors = false; - if (count($products_need_cache)) - $colors = Product::getAttributesColorList($products_need_cache); - - Tools::enableCache(); - foreach ($this->cat_products as &$product) - { - $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']] - )); - 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->addColorsToProductList($this->cat_products); $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 */ diff --git a/controllers/front/ManufacturerController.php b/controllers/front/ManufacturerController.php index 4cc8d6b62..665ad295a 100644 --- a/controllers/front/ManufacturerController.php +++ b/controllers/front/ManufacturerController.php @@ -97,9 +97,13 @@ class ManufacturerControllerCore extends FrontController $this->manufacturer->description = Tools::nl2br(trim($this->manufacturer->description)); $nbProducts = $this->manufacturer->getProducts($this->manufacturer->id, null, null, null, $this->orderBy, $this->orderWay, true); $this->pagination((int)$nbProducts); + + $products = $this->manufacturer->getProducts($this->manufacturer->id, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); + $this->addColorsToProductList($products); + $this->context->smarty->assign(array( 'nb_products' => $nbProducts, - 'products' => $this->manufacturer->getProducts($this->manufacturer->id, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), + 'products' => $products, 'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''), 'manufacturer' => $this->manufacturer, 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM') diff --git a/controllers/front/SearchController.php b/controllers/front/SearchController.php index 3e1a543a2..5e686d1ce 100644 --- a/controllers/front/SearchController.php +++ b/controllers/front/SearchController.php @@ -75,6 +75,9 @@ class SearchControllerCore extends FrontController Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); + + $this->addColorsToProductList($search['result']); + $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $search['result'], @@ -83,7 +86,7 @@ class SearchControllerCore extends FrontController 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } - else if (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) + elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')))); @@ -93,6 +96,9 @@ class SearchControllerCore extends FrontController Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); + + $this->addColorsToProductList($search['result']); + $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $search['result'], @@ -100,12 +106,15 @@ class SearchControllerCore extends FrontController 'search_query' => $query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } - else if (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) + elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); + + $this->addColorsToProductList($search['result']); + $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module diff --git a/controllers/front/SupplierController.php b/controllers/front/SupplierController.php index 78fda9152..ec31da243 100644 --- a/controllers/front/SupplierController.php +++ b/controllers/front/SupplierController.php @@ -99,9 +99,13 @@ class SupplierControllerCore extends FrontController $this->supplier->description = Tools::nl2br(trim($this->supplier->description)); $nbProducts = $this->supplier->getProducts($this->supplier->id, null, null, null, $this->orderBy, $this->orderWay, true); $this->pagination((int)$nbProducts); + + $products = $this->supplier->getProducts($this->supplier->id, $this->context->cookie->id_lang, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); + $this->addColorsToProductList($products); + $this->context->smarty->assign(array( 'nb_products' => $nbProducts, - 'products' => $this->supplier->getProducts($this->supplier->id, $this->context->cookie->id_lang, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), + 'products' => $products, 'path' => ($this->supplier->active ? Tools::safeOutput($this->supplier->name) : ''), 'supplier' => $this->supplier, 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM') diff --git a/themes/default/product-list.tpl b/themes/default/product-list.tpl index 08c6152e3..45efa3927 100644 --- a/themes/default/product-list.tpl +++ b/themes/default/product-list.tpl @@ -43,7 +43,7 @@
{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
- {$product.color_list} + {if isset($product.color_list)}{$product.color_list}{/if}