Jump to content

Get cover image from product images


AlluB
 Share

Recommended Posts

Hello,

 

I want to use a image as a cover for a product, the image box that says 'cover' it's ticked but i don't know how to get that image. It makes any sense?

This does not work,

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

Thank you!

Share this post


Link to post
Share on other sites

 

Try this instead :

<img src="{$link->getImageLink($product.link_rewrite, Product::getCover($product.id), 'home_default')}">

 

Now the page is blank. :)

 

I want every product to have it's own cover in the header. I don't know if it's make any sense.

Edited by AlluB (see edit history)

Share this post


Link to post
Share on other sites

Active the debug to see where is the error.

 

In the header of what page? Can't you use a module for that? Have you seen if the current image is already the cover? (like in product list)

In product.tpl, that's what i'm editing. It doesn't have any cover, i have the header text and above that it should be an image.

Share this post


Link to post
Share on other sites

Product::getCover returns as array

 

$images = Product::getCover($id_product);
$image_url = $this->context->link->getImageLink($product->link_rewrite, $images['id_image'], ImageType::getFormatedName('home'));

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Product::getCover returns as array

 

$images = Product::getCover($id_product);

$image_url = $this->context->link->getImageLink($product->link_rewrite, $images['id_image'], ImageType::getFormatedName('home'));

I'm new to Prestashop. Can you please tell me where or how to write this code in product.tpl?

 

Thank you.

Edited by AlluB (see edit history)

Share this post


Link to post
Share on other sites

err, not really, depends on what you're trying to achieve, and your theme, the code above is for use within a module, not a template.

 

If you're trying to get the product image in the header, i.e. you want it near the top, you'll have to use a module, as Gabriel said, or create your own.

Share this post


Link to post
Share on other sites

err, not really, depends on what you're trying to achieve, and your theme, the code above is for use within a module, not a template.

 

If you're trying to get the product image in the header, i.e. you want it near the top, you'll have to use a module, as Gabriel said, or create your own.

I'm using the Transformer theme.

Share this post


Link to post
Share on other sites

  • 2 years later...
  • 2 months later...
  • 1 year later...
On 9/24/2019 at 8:23 AM, dinesh badrukhiya said:

Use this code instead:

        {if $product.cover}
          {assign var='coverImage' value=Product::getCover($product->id)}
          {assign var='coverImageId' value="{$product->id}-{$coverImage.id_image}"}
          <a class="thumbnail product-thumbnail" href="{$product.canonical_url}">
            <img src="{$link->getImageLink($product.link_rewrite, $coverImageId, 'home_default')}" alt="{if !empty($product.cover.legend)}{$product.cover.legend}{else}{$product.name|truncate:30:'...'}{/if}" data-full-size-image-url="{$product.cover.large.url}" />
          </a>
        {else}
          <a class="thumbnail product-thumbnail" href="{$product.canonical_url}">
            <img src="{$urls.no_picture_image.bySize.home_default.url}" />
          </a>
        {/if}

Edited by Prestapepe (see edit history)

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More