// add color list to some controllers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</a>
|
||||
<h3>{if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}<a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></h3>
|
||||
<p class="product_desc"><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}" >{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}</a></p>
|
||||
{$product.color_list}
|
||||
{if isset($product.color_list)}{$product.color_list}{/if}
|
||||
</div>
|
||||
<div class="right_block">
|
||||
{if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}<span class="on_sale">{l s='On sale!'}</span>
|
||||
|
||||
Reference in New Issue
Block a user