Question

After a recent update from Magento 2.1.7 to 2.3.3. product images are not displayed. I believe it is cache related, and most common (if not only) solution that I have found is to run:

php bin/magento catalog:images:resize

However, since there are about 12000 images, it takes forever to run, and it seems that it is slowing down with time. I have tried to run it several times. It ran from over 6-8h and it always comes to about 80% and there it seems to stop.

I have also tried: - cache flush, clean - manually flush images cache from admin - delete all images - import new images with different filenames

In the beginning, it was showing most of the images, and where there were none it showed Magento icon placeholder. Now, it is just "blank" (white) and I have noticed that all images are called like this:

https://www.myshop.com/pub/media/catalog/product/cache/97da63c2767447ab58ac94bd37bac16d/import/0340041-ups-apc-back-cs-350va.jpg

When I go to the location:

pub/media/catalog/product

At first, I didn't see the cache directory, but after I started opening products in a detail view I noticed that the cache directory has generated. However, the hash from directory where my images are and the one on the frontend in image source is not the same.

Also - on the homepage, there are modules with listed products, and when the homepage is opened no cache directory is generated...

Is it possible that my theme is using the wrong URL for cached images? And if it does - where do I change this? The theme is not supported by developers any more so... it is left to me :)


Here is one view that I found that is using product image

public_html/app/design/frontend/tv_themevast_package/default/Magento_Catalog/templates/product/list.phtml

<?php // Product Image ?>
<div class="product-photo">
    <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
        <?php $productImageThumb = $block->getImage($_product, 'category_page_grid-1');?>
        <span class="image0 image-switch">
            <?php echo $productImage->toHtml(); ?>
        </span>
        <span class="image1 image-switch">
            <?php echo $productImageThumb->toHtml(); ?>
        </span>
    </a>
    <div class="new-sale-label">
        <?php
         $specialprice = $_product->getSpecialPrice();
         $specialPriceFromDate = $_product->getSpecialFromDate();
         $specialPriceToDate = $_product->getSpecialToDate();
         $_price=$_product->getPrice();
         $_finalPrice=$_product->getFinalPrice();
         $today = time();?>

         <?php 
         if ($specialprice) {
          if ($today >= strtotime($specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime($specialPriceFromDate) && is_null($specialPriceToDate)) { ?>
           <span class="label-product label-sale">
                <?php if($_finalPrice < $_price): ?>
                  <?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
                    <?php echo __('-%1',$_savePercent."%");?>
                  <?php endif; ?>
           </span>
          <?php }
         }
         ?>
         <?php
         $now = date("Y-m-d");
         $newsFrom = substr($_product->getNewsFromDate(), 0, 10);
         $newsTo = substr($_product->getNewsToDate(), 0, 10);

         if (($newsTo != '' || $newsFrom != '') && !$specialprice) {
         if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) {?>
           <span class="label-product label-new"><?php echo __('New'); ?></span>
         <?php }
         } ?>
       </div>
       <div class="quickview-product">
            <a  data-role="quickview-button" data-id="<?php echo $_product->getId(); ?>" href="<?php echo $block->getUrl('quickview/product/quickview/id/' . $_product->getId()) ?>" title="" class="ajax diamond tooltip-toggle" data-placement="top" data-original-title="<?php echo ('Quick view') ?>">
            <?php echo $block->escapeHtml(__('Quick View')); ?>
            </a>
        </div>

</div>
Was it helpful?

Solution

All images/products come from "import". I found import files in /pub/media/catalog/product/import. Almost all images there were invalid, because of an error while grabbing them in import. So I have manually deleted all files from that directory using:

rm -fr *

After that I ran command:

php bin/magento catalog:images:resize

and it was like 100x faster than before.

I am still facing an issue where "old" images are stored in database tables:

dev_catalog_product_entity_varchar
dev_catalog_product_entity_media_gallery

And will try to purge them using this: https://github.com/magento-hackathon/EAVCleaner.

Meanwhile, after running catalog:image:resize function all images were repaired.

@jiheison THANK YOU ALL FOR YOUR HELP! I really appreciate it. It gave me some good insight :)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top