// add color list on product listing
This commit is contained in:
@@ -3045,6 +3045,35 @@ class ProductCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getAttributesColorList(Array $products, $have_stock = true)
|
||||
{
|
||||
if (!count($products))
|
||||
return array();
|
||||
|
||||
if (!$res = Db::getInstance()->executeS('
|
||||
SELECT pa.id_product, a.color, a.id_attribute, pac.id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = product_attribute_shop.id_product_attribute)
|
||||
JOIN '._DB_PREFIX_.'attribute a ON (a.id_attribute = pac.id_attribute)
|
||||
JOIN '._DB_PREFIX_.'attribute_group ag ON (ag.id_attribute_group = ag.id_attribute_group)
|
||||
WHERE pa.id_product IN ('.implode(array_map('intval', $products), ',').') AND ag.is_color_group = 1
|
||||
GROUP BY pa.id_product, color
|
||||
'))
|
||||
return false;
|
||||
|
||||
$colors = array();
|
||||
foreach ($res as $row)
|
||||
{
|
||||
if (Tools::isEmpty($row['color']))
|
||||
continue;
|
||||
|
||||
$colors[(int)$row['id_product']][] = array('id_product_attribute' => (int)$row['id_product_attribute'], 'color' => $row['color']);
|
||||
}
|
||||
|
||||
return $colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available attribute groups
|
||||
*
|
||||
|
||||
@@ -356,4 +356,9 @@ abstract class ControllerCore
|
||||
$this->context->cookie->write();
|
||||
$this->context->smarty->display($content);
|
||||
}
|
||||
|
||||
protected function isCached($template, $cacheId = null, $compileId = null)
|
||||
{
|
||||
return $this->context->smarty->isCached($template, $cacheId, $compileId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,10 +199,38 @@ 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', 'productlist_colors|'.$product['id_product']))
|
||||
$products_need_cache[] = (int)$product['id_product'];
|
||||
}
|
||||
unset($product);
|
||||
|
||||
$colors = array();
|
||||
if (count($products_need_cache))
|
||||
$colors = Product::getAttributesColorList($products_need_cache);
|
||||
|
||||
if (count($colors))
|
||||
{
|
||||
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(
|
||||
'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();
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('nb_products', $this->nbProducts);
|
||||
|
||||
@@ -146,4 +146,22 @@ ul#product_list {
|
||||
background:url(../img/arrow_right_1.png) no-repeat 100% 4px transparent
|
||||
}
|
||||
#product_list li .lnk_view:hover {text-decoration:underline}
|
||||
|
||||
|
||||
#color_to_pick_list {
|
||||
list-style-type:none;
|
||||
width:125px;
|
||||
float:left;
|
||||
}
|
||||
|
||||
#color_to_pick_list li {
|
||||
float:left;
|
||||
clear:none;
|
||||
padding:0;
|
||||
margin-bottom:1px;
|
||||
}
|
||||
|
||||
#color_to_pick_list li a {
|
||||
display:block;
|
||||
height:20px;
|
||||
width:20px;
|
||||
}
|
||||
|
||||
@@ -43,6 +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}
|
||||
</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