how to display in product-list the cover image and the second image of a product

蹲街弑〆低调 提交于 2020-02-08 06:59:20

问题


i'm new to prestashop 1.6 and like to display 2 images per product in the product-list.tpl. I see that getImageLink display the cover image. Is there a similar function with an argument corresponding to the column position ? thank you regards


回答1:


Rather than writing function in Product.php simply get second image by adding +1 next to id_image

src="{$link->getImageLink($product.link_rewrite, $product.id_image+1, 'home_default')|escape:'html':'UTF-8'}"



回答2:


1/ edit classes/Product.php and add the function to read the second image:

public function getProductsSecondImg($product_id){
$sqlQ = 'SELECT id_image, id_product from `'._DB_PREFIX_.'image` WHERE id_product="'.$product_id.'" AND position=2';
$result = Db::getInstance()->ExecuteS($sqlQ);
return $result[0]['id_product'].'-'.$result[0]['id_image'];
}

add the definition of the second image :

$row['id_image2'] = Product::getProductsSecondImg((int)$row['id_product']);

after

$row['id_image'] = Product::defineProductImage($row, $id_lang);

2/ Edit the themes/mytheme/product-list.tpl and copy/paste the html tag img of the cover image :

<img ... src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default') .../>

inside :

<div class="color-list-container"> ... </div>

but this time use $product.id_image2 for the 2nd arg of getImageLink

it works for my 1.6.1.3. The second image must be present or a default one is displayed. With the help of this blog site.



来源:https://stackoverflow.com/questions/40267160/how-to-display-in-product-list-the-cover-image-and-the-second-image-of-a-product

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!