Prestashop 1.7.6:在文本自定义区域中获取并显示2°产品图像作为背景

时间:2020-03-02 11:24:28

标签: prestashop prestashop-1.7

我正在使用prestashop 1.7.6。在产品页面上:在background-image文本自定义中(当文本自定义处于活动状态时),我需要将第二(2°)或第三(3°)图像显示为textarea

example image getting first product image 在所附的照片中,我得到了第一张图像,但我不知道如何得到第二张图像。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

在Product.php类中创建一个新方法,以获取图像:

 public static function getImagesByID($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;
} 

并在smarty模板中使用静态功能

{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}
相关问题