Reputation: 41
I need to show a different cover image (the second, or the last, it's not important, all but not the first) only for a specific block: ps_bestseller
.
The only thing I found is this code was this link, but it works only for the 1.6 version:
This is my default code:
{block name='product_thumbnail'}
{if $product.cover}
<a href="{$product.url}" class="thumbnail product-thumbnail">
<img
src = "{$product.cover.bySize.home_default.url}"
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 href="{$product.url}" class="thumbnail product-thumbnail">
<img
src = "{$urls.no_picture_image.bySize.home_default.url}"
>
</a>
{/if}
{/block}
When I try to edit the code it returns a blank page. Any suggestion?
Upvotes: 1
Views: 1822
Reputation: 1273
Create an override file that will be named Link.php
in override/classes/
with this content:
<?php
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use PrestaShop\PrestaShop\Core\Feature\TokenInUrls;
class Link extends LinkCore
{
public function getLastImageLink($id_product, $product_name, $type = null) {
$maxId = Db::getInstance()->getValue('SELECT id_image FROM `'._DB_PREFIX_.'image` WHERE id_product = '.(int)$id_product.' ORDER BY position DESC');
return $this->getImageLink($product_name, $id_product.'-'.$maxId, $type = null);
}
}
Ensuite dans le tpl pour appeler l'url de votre image mettez :
{$link->getLastImageLink($product.id, $product.name, 'large')}
Regards
Upvotes: 1