问题
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