Jump to content

Show default imagen when the product image is broken in Prestashop 1.7


Recommended Posts


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
        No existe imagen
      <!-- End Code I have inserted -->
          <a href="{$product.url}" class="thumbnail product-thumbnail">
              alt="{if !empty($product.cover.legend)}{$product.cover.legend}{else}{$product.name|truncate:30:'...'}{/if}"
          <a href="{$product.url}" class="thumbnail product-thumbnail">
            <img src="https://alcasum.es/tienda2020/img/p/es-default-cart_default.jpg" />

Thanks for all

Share this post

Link to post
Share on other sites

  • 1 year later...

Can you please know, know how to solve this problem ??
I theme Drama, and I can't find product-list.tpl anywhere
how to solve the problem du PS
please help me how and what to modify?
possible that a CMS like PS does not take into account something so IMPORTANT FUNDAMENTAL I find it really as children who do not take into account, considering that PS is used for thousands of products in csv is ... absurd!

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

  • Create New...

Important Information

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