4

I am getting error with Magento 2.4.4 & 2.4.5

Here is my line of code

<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>

3 Answers 3

4

In Magento 2.4.4 was changed some important logic in vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

  1. getProductDetailsHtml renders for non saleable products

  2. Added options logic

                                            <?php $options = $block->getData('viewModel')->getOptionsData($_product); ?>
                                            <?php foreach ($options as $optionItem): ?>
                                                <input type="hidden"
                                                       name="<?= $escaper->escapeHtml($optionItem['name']) ?>"
                                                       value="<?= $escaper->escapeHtml($optionItem['value']) ?>">
                                            <?php endforeach; ?>
  1. strpos to $pos to:
                <?= ($pos && strpos($pos, $viewMode . '-actions')) ?
                /* @noEscape */ $secureRenderer->renderStyleAsTag(
                    $position,
                    'product-item-info_' . $_product->getId() . ' div.product-item-actions'
                ) : '' ?>
                                <?= ($pos && strpos($pos, $viewMode . '-secondary')) ?
                                    /* @noEscape */ $secureRenderer->renderStyleAsTag(
                                        $position,
                                        'product-item-info_' . $_product->getId() . ' div.actions-secondary'
                                    ) : '' ?>

  1. bottom toolbar renders with:
    <?= $block->getChildBlock('toolbar')->setIsBottom(true)->toHtml() ?>

I'm strongly suggest to compare your design file with core file and make related changes

1

Insted of passing null in the method strpos() pass an empty string if the variable is null i check the variable first and then use them in code

here is my code

<?php //Modifications 29 August 2022 (hassan)
      if(!$pos)
       {
          $pos = '';
       }
       if(!$viewMode)
       {
          $viewMode = '';
       }
  ?>

EDIT:

You may also just use the same syntax used on your question, and use empty() to make sure your variables are empty or not:

$pos = !empty($pos) ? $pos : '';

$viewMode = !empty($viewMode) ? $viewMode : '';
1
<?= strpos($pos, $viewMode . '-primary') ?
                                    /* @noEscape */ $secureRenderer->renderStyleAsTag(
                                        $position,
                                        'product-item-info_' . $_product->getId() . ' div.actions-primary'
                                    ) : '' ?>

Your Answer

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

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