Jump to content

[1.6] Different image for cover in list and in preview/view.


Recommended Posts

Hi there, is it possible to have one image as a  cover for an item when it is in a list, and another image for a cover when it is previewed or viewed? Said in other words the item to be seen with image #1 in the list and when opened(or previewed) Image #2 to load as cover.Thank you!

Link to comment
Share on other sites

Yep thats possible. If u just rightclick on the category picture and on the large picture u notice that the category one is safed in home-default and the product in large-default so you can upload your pircute in that folder with the right size and use it. Its definitly not the easyest solution and im pretty sure there are other, easyer solutions.

  • Like 1
Link to comment
Share on other sites

Its a default sice you can set up in the BO by default this should be 250x250px so you can just resize it and upload it via ftp in the folder. But ye, properly there is a easyer way. Im not confident with the coding part and so on. Just searched a solution for you and found that out.

Link to comment
Share on other sites

Ah wait, let me check that. I got what you mean, needed some time for me to figure it out as well, used that solution to change the sub category icons. Ill respond to you shortly

 

Okay i belive i got it. It should work like that /img/p 

 

p for product than you get numbers like 1,2,3,4 there the products get stored with the id. that means the first number so 57 should be stored in 5 than and the next number means the 2. number so 57 should be located in /img/p/5/7 and than you see all the images.

Edited by Vire (see edit history)
Link to comment
Share on other sites

i've got an idea in my head with little modification of controller. but before i will write solution i have to ask about something.

 

 

for a cover when it is previewed or viewed?

you mean product page? or something else?

Link to comment
Share on other sites

i've got an idea in my head with little modification of controller. but before i will write solution i have to ask about something.

you mean product page? or something else?

 

I need one picture to be for cover when the product is seen in its category, when searched in a search list, and when seen in any other list, for example here - http://bgpokerclub.com/sangado/en/5-classic

 

and another picture to be for cover, or default image, when the product is "opened" and seen here - http://bgpokerclub.com/sangado/en/classic/8-sredizemnomorski-briz.html

 

Im sorry for the way I explain what I mean, but Im not sure of the proper terms and names... :)

Link to comment
Share on other sites

ok, in productController paste this funciton
 

    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 in product.tpl file you can use:

 {assign var="pImages" value=ProductController::geImagesByID($smarty.get.id_product,1)}
                    {if $pImages}
                        {foreach from=$pImages item=image name=images}
                            <img src="{$link->getImageLink($product->link_rewrite, $image, 'large_default')}"  alt="{$product->legend|escape:'htmlall':'UTF-8'}" />
                        {/foreach}
                    {/if}  

to display second image instead of original one :-)

  • Like 1
Link to comment
Share on other sites

Thank you very much Vekia, have a lame question though  :unsure: . Where do I find the product.tpl file? I found a couple of them in different folders, cant decide which one is the one I need to edit. Does it matter where in the body I paste the additional code? As for the "then in product.tpl file you can use:", just to make sure, u mean as for productController, to add this code to it? Thanks again and sorry for my silly questions.

Link to comment
Share on other sites

product.tpl file is a file located in your theme directory.

themes/your-theme/product.tpl

your-theme is a name of theme that you currently use

 

regarding to other questions

 

paste this code:

    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;
    }

before last closing bracket in controllers/front/ProductController.php file

  • Like 2
Link to comment
Share on other sites

sorry for late reply,

im back :D

 

in product.tpl you can find code:

<span id="view_full_size">
{if $jqZoomEnabled && $have_image && !$content_only}
<a class="jqzoom" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" rel="gal1" href="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'thickbox_default')|escape:'html':'UTF-8'}" itemprop="url">
<img itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}"/>
</a>
{else}
<img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/>
{if !$content_only}
<span class="span_link no-print">{l s='View larger'}</span>
{/if}
{/if}
</span>
 
instead of read code use code that i suggested to use in tpl file
 
enjoy the changes ;)
Link to comment
Share on other sites

Thanks Vekia, it is working, but only in quick preview. Here it is what I got as result.

 

1. In Quick Preview it loads the 2nd Image as cover, but it seems to disable the other 2 images - they are there but can not be selected and viewed in the "main image spot"

 

2. In regular(full) product view it doesnt seem to work - 1st Image is still opened as cover.

 

Here is a link to my shop. Thank you.

 

 

UPDATE:

 

The above is true with  JqZoom ENABLED(which is my default setup). Here is the result after disabling the  JqZoom:

 

1. No changes here -  In Quick Preview it loads the 2nd Image as cover, but it seems to disable the other 2 images - they are there but can not be selected and viewed in the "main image spot"

 

2. In regular(full) product view, Image 2 is loaded as cover. Clicking on images 1 or 3 loads them directly in "full size", instead of getting them in the place of the cover image. When click on the cover - image 2 - it loads image 1 in full size mode.

 

:)

Edited by mnmak (see edit history)
Link to comment
Share on other sites

  • 10 months later...

Hi, trying to use this code with changing the default image on a product page to the 2nd image.

 

It only partly works, it will correctly load the 2nd image by default, but the rollover on the thumbnails no longer works?

 

Any one able to help? 

 
Prestashop 1.6.0.11
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

Hi all, does anyone know how to get this working in version 1.6.1.0?

 

I've just updated my store and the value part below that worked in 1.6.0.14 crashes my product template and nothing will load.

 

"{assign var="pImages" value=ProductController::geImagesByID($smarty.get.id_product,1)}"

Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...