Created
March 19, 2018 08:54
-
-
Save Casper-O/e7e46f3b708aa03faa2c57fa429f357a to your computer and use it in GitHub Desktop.
Prestashop 1.6.X - Fix attribute color list doesn't show on product list if turning on smarty cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FrontController extends FrontControllerCore | |
{ | |
public function addColorsToProductList(&$products) | |
{ | |
if (!is_array($products) || !count($products) || !file_exists(_PS_THEME_DIR_.'product-list-colors.tpl')) { | |
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']; | |
}else{ | |
$product['color_list'] = $this->context->smarty->createTemplate(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product']))->fetch(); | |
} | |
} | |
unset($product); | |
$colors = false; | |
if (count($products_need_cache)) { | |
$colors = Product::getAttributesColorList($products_need_cache); | |
Tools::enableCache(); | |
foreach ($products as &$product) { | |
if (in_array($product['id_product'], $products_need_cache)){ | |
$tpl = $this->context->smarty->createTemplate(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product'])); | |
if (isset($colors[$product['id_product']])) { | |
$tpl->assign(array( | |
'id_product' => $product['id_product'], | |
'colors_list' => $colors[$product['id_product']], | |
'link' => Context::getContext()->link, | |
'img_col_dir' => _THEME_COL_DIR_, | |
'col_img_dir' => _PS_COL_IMG_DIR_ | |
)); | |
$product['color_list'] = $tpl->fetch(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product'])); | |
} else { | |
$product['color_list'] = ''; | |
} | |
} | |
} | |
Tools::restoreCacheSettings(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how yo use:
Original Author: iTiaNex
Source: PrestaShop/PrestaShop#7876 (comment)