1

congratulations to the community, I use it a lot to find solutions that are always useful, but this time I'm completely blocked.

After doing a setup: upgrade and a setup: di: compile following installation of Welt Pixels, all products in the categories are gone. I can see them in the Products section (in the backend) but in the Frontend they seem "invisible". In the categories it doesn't tell me that there are no products, they just aren't seen.

I've tried re-indexing, clearing cache, and all ordinary operations, but nothing to do.

I tried to see the log files (system.log) which gives me this error:

main.CRITICAL: Warning: Invalid argument supplied for foreach() in /var/www/html/magento/vendor/magento/module-catalog/view/frontend/templates/product/image_with_borders.phtml on line 27 [] []

In the phtml file mentioned in the logs I find this:

<span class="product-image-container product-image-container-<?= /* @noEscape */ $block->getProductId() ?>">
    <span class="product-image-wrapper">
        <img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
            <?php foreach ($block->getCustomAttributes() as $name => $value): ?>
                <?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>" 
            <?php endforeach; ?>
            src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
            loading="lazy"
            <?php if ($borders || $enableLazyLoadingWithoutBorders): ?>
                width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
                height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
            <?php else: ?>
                max-width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
                max-height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
            <?php endif; ?>
            alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
</span>

Specifically, line 27 reads:

<?php foreach ($block->getCustomAttributes() as $name => $value): ?>

I am hoping for your guidance, I can't figure out if it's an array problem or something.

4
  • have you used any custom extensions? Sep 29, 2020 at 13:22
  • Thanks for comment. I have one Extension enabled "LiteExtensione migration from Woocommerce", but i have put them few days ago (i have already done a setup:upgrade before, and i haven't had problem). Today i've try to install Welt Pixels free with composer for the slider, and the installation was good. But after setup:upgrade i've seen the error
    – Alberto
    Sep 29, 2020 at 13:27
  • Try to disabled that Welt Pixels extension and then try. Sep 30, 2020 at 4:23
  • @Alberto i have same issue facing , which changes throgh you have fixed? Feb 24, 2021 at 7:39

2 Answers 2

0

I have the same problem, so I removed the lines below and started to display the products. I don't know if this will affect other features.

<?php foreach ($block->getCustomAttributes() as $name => $value): ?> <?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>" <?php endforeach; ?>

1
  • Hii this one works but might break the functionality for future, have you come up with why this issue happens or any alternate solutions ? Sep 6, 2022 at 17:04
0

I came across the similar issue while upgrade 2.3.6 to 2.4.3 and while debugging, i found $block->getCustomAttributes() returning empty string and hence <?php foreach ($block->getCustomAttributes() as $name => $value): ?> statement throws exception saying invalid argument supplied to foreach().

I am not sure about the root cause of this but i did the following workaround to avoid any future conflicts with functionality.

<?php if (!empty($block->getCustomAttributes())): ?>
        <?php foreach ($block->getCustomAttributes() as $name => $value): ?>
            <?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtml($value) ?>"
        <?php endforeach; ?>
    <?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.