sportivo147 Posted September 14, 2014 Share Posted September 14, 2014 Hello... i'm using PS 1.6 and i have a product with two images. How can i show both images in the product listing page instead of one showing ? I have read that i must change the sql query from cover = 1 to position = 2 and use some code to add in the product-list.tpl. thx. Link to comment Share on other sites More sharing options...
vekia Posted September 14, 2014 Share Posted September 14, 2014 what is your prestashop version? Link to comment Share on other sites More sharing options...
sportivo147 Posted September 15, 2014 Author Share Posted September 15, 2014 what is your prestashop version? I'm using 1.6.0.9 Link to comment Share on other sites More sharing options...
vekia Posted September 15, 2014 Share Posted September 15, 2014 it's necessary to later code a little. in product.php class use this: public static function geImagesByID($id_product, $limit = 2){ $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)($id_product) . ' ORDER BY position ASC LIMIT 1, ' . $limit); $toReturn = array(); if(!$id_image) return; else foreach($id_image as $image) $toReturn[] = $id_product . '-' . $image['id_image']; return $toReturn; } then you will be able to use this static function in .tpl file to get second product image :-) 1 Link to comment Share on other sites More sharing options...
sportivo147 Posted September 16, 2014 Author Share Posted September 16, 2014 it's necessary to later code a little. in product.php class use this: public static function geImagesByID($id_product, $limit = 2){ $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)($id_product) . ' ORDER BY position ASC LIMIT 1, ' . $limit); $toReturn = array(); if(!$id_image) return; else foreach($id_image as $image) $toReturn[] = $id_product . '-' . $image['id_image']; return $toReturn; } then you will be able to use this static function in .tpl file to get second product image :-) ok... and how i call this static function in tpl file ?? I mean what code i must write ? Link to comment Share on other sites More sharing options...
vekia Posted September 16, 2014 Share Posted September 16, 2014 you can use code like: {assign var="pImages" value=Product::geImagesByID($product.id_product, 2)}{foreach from=$pImages item=image name=images} <img src="{$link->getImageLink($product.link_rewrite, $image, 'home_default')}" {if $smarty.foreach.images.first}class="current img_{$smarty.foreach.images.index}"{else} class="img_{$smarty.foreach.images.index}" style="display:none;"{/if} alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if}/> {/foreach} 1 Link to comment Share on other sites More sharing options...
sportivo147 Posted September 16, 2014 Author Share Posted September 16, 2014 it's necessary to later code a little. in product.php class use this: public static function geImagesByID($id_product, $limit = 2){ $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)($id_product) . ' ORDER BY position ASC LIMIT 1, ' . $limit); $toReturn = array(); if(!$id_image) return; else foreach($id_image as $image) $toReturn[] = $id_product . '-' . $image['id_image']; return $toReturn; } then you will be able to use this static function in .tpl file to get second product image :-) I copy this code to the classes/product.php but white page appears.... Link to comment Share on other sites More sharing options...
sportivo147 Posted September 24, 2014 Author Share Posted September 24, 2014 you can use code like: {assign var="pImages" value=Product::geImagesByID($product.id_product, 2)}{foreach from=$pImages item=image name=images} <img src="{$link->getImageLink($product.link_rewrite, $image, 'home_default')}" {if $smarty.foreach.images.first}class="current img_{$smarty.foreach.images.index}"{else} class="img_{$smarty.foreach.images.index}" style="display:none;"{/if} alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if}/> {/foreach} Thanks Vekia !!! It works excellent... Thank you! Problem SOLVED Link to comment Share on other sites More sharing options...
sportivo147 Posted September 28, 2014 Author Share Posted September 28, 2014 Just a small problem... It works excellent on List View. If you change it to grid mode then the first image is smaller than the second image. Link to comment Share on other sites More sharing options...
vekia Posted September 28, 2014 Share Posted September 28, 2014 Just a small problem... It works excellent on List View. If you change it to grid mode then the first image is smaller than the second image. any chance to see it live? Link to comment Share on other sites More sharing options...
sportivo147 Posted September 28, 2014 Author Share Posted September 28, 2014 any chance to see it live? We have installed it localhost for the moment. But i can show you what i mean from these pictures : Link to comment Share on other sites More sharing options...
vekia Posted September 28, 2014 Share Posted September 28, 2014 can you try to add to <img> class="img-responsive" ? Link to comment Share on other sites More sharing options...
sportivo147 Posted September 29, 2014 Author Share Posted September 29, 2014 can you try to add to <img> class="img-responsive" ? iT WORKS !!! Thank you Vekia. Link to comment Share on other sites More sharing options...
rtvt Posted November 3, 2014 Share Posted November 3, 2014 it's necessary to later code a little. in product.php class use this: public static function geImagesByID($id_product, $limit = 2){ $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)($id_product) . ' ORDER BY position ASC LIMIT 1, ' . $limit); $toReturn = array(); if(!$id_image) return; else foreach($id_image as $image) $toReturn[] = $id_product . '-' . $image['id_image']; return $toReturn; } then you will be able to use this static function in .tpl file to get second product image :-) Hello, great solution. Does there is any way to put this new class to one of the THEME files?? It will allow to have this class with theme installation on new shop, but not coping products.php to classes or override folder via ftp. Can you help with it, please? Link to comment Share on other sites More sharing options...
Recommended Posts