Hello,
After doing an import of more than 25000 products with the Prestashop importer in a 1.7 installation, I find that I have 5000 products whose images are broken. The importer tried to upload images but they did not exist. I have been trying to make the image show me a default image when the image is broken directly, I almost have it, but when trying to use the file_exists function I have discovered that it needs the absolute URL and I can only get the relative one. Does anyone have any idea how to do it?
I put the code that I have edited in /themes/child-classic-theme/templates/catalog/_partials/miniatures/product.tpl
<article class="product-miniature js-product-miniature" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}" itemscope itemtype="http://schema.org/Product">
<div class="thumbnail-container">
{block name='product_thumbnail'}
{if $product.cover}
<!-- Code I have inserted -->
{assign var='coverImage' value=Product::getCover($product->id)}
{assign var='coverImageId' value="{$product->id}-{$coverImage.id_image}"}
{assign var='urlImagen' value="{$link->getImageLink($product.link_rewrite, $coverImageId)}"}
<!--urlImagen is the relative path to the image, but I need the absolute path oh the image because "file_exits" function uses that path -->
<!-- Code that checks if the image exists, when I get this to work the change would be in the code below -->
{if (file_exists($urlImagen))}
Existe imagen
{else}
No existe imagen
{/if}
<!-- End Code I have inserted -->
<a href="{$product.url}" class="thumbnail product-thumbnail">
<img
src="{$product.cover.bySize.home_default.url|default:'{$urls.img_prod_url}img/p/es-default-cart_default.jpg'}"
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="https://alcasum.es/tienda2020/img/p/es-default-cart_default.jpg" />
</a>
{/if}
{/block}
Thanks for all