Jump to content

Show Second Image in Product listing page


sportivo147

Recommended Posts

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 :-)

  • Like 1
Link to comment
Share on other sites

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

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}
  • Like 1
Link to comment
Share on other sites

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

 

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

  • 1 month later...

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

×
×
  • Create New...