3

Can anyone have faced the below error while opening the product listing page at the storefront?

Running instance on the Magento version 2.4 vanilla. No third-party modules/themes were installed.

A stack trace is as follows:

report.CRITICAL: Exception: Warning: Object of class Magento\Framework\Phrase could not be converted to int in /var/www/html/mage/vendor/magento/module-catalog/view/frontend/templates/product/list/toolbar/limiter.phtml on line 26 in /var/www/html/mage/vendor/magento/framework/App/ErrorHandler.php:62
-Stack trace:
-#0 /var/www/html/mage/vendor/magento/module-catalog/view/frontend/templates/product/list/toolbar/limiter.phtml(26): Magento\Framework\App\ErrorHandler->handler()
-#1 /var/www/html/mage/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('...')
-#2 /var/www/html/mage/vendor/magento/framework/View/Element/Template.php(263): Magento\Framework\View\TemplateEngine\Php->render()
-#3 /var/www/html/mage/generated/code/Magento/Catalog/Block/Product/ProductList/Toolbar/Interceptor.php(401): Magento\Framework\View\Element\Template->fetchView()
-#4 /var/www/html/mage/vendor/magento/module-catalog/view/frontend/templates/product/list/toolbar.phtml(21): Magento\Catalog\Block\Product\ProductList\Toolbar\Interceptor->fetchView()
-#5 /var/www/html/mage/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('...')
-#6 /var/www/html/mage/vendor/magento/framework/View/Element/Template.php(263): Magento\Framework\View\TemplateEngine\Php->render()
-#7 /var/www/html/mage/generated/code/Magento/Catalog/Block/Product/ProductList/Toolbar/Interceptor.php(401): Magento\Framework\View\Element\Template->fetchView()
asked Aug 5, 2022 at 12:57
0

3 Answers 3

10

The issue got fixed but somehow it was not included in the Magento 2.4.5-p1 release. This most likely will be fixed in the Magento 2.4.5-p2 patch which is planned to be released in March 2023 (Release plan).

The fix can be looked up here (Issue fixing commit). The fix looks like this:

 <option value="<?= $block->escapeHtmlAttr($_key) ?>"
 <?php if ($block->isLimitCurrent($_key)):?>
 selected="selected"
 <?php endif ?>>
 <?= $block->escapeHtml(
 is_numeric($_limit) ? $localeFormatter->formatNumber((int) $_limit) : $_limit
 ) ?>
 </option>
answered Nov 17, 2022 at 8:50
1
3

It took a while to find out the root cause of this issue, there is a code commit a while ago that broke.

For a quick fix, look for the below line code mostly Line26, and remove the format-number function for All. It's not typecasting error, it is an warning related to the localization of Arabic numbers.

From:

<?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>

To


<?php if (strtoupper($_key) == 'ALL'): ?>
 <?= $block->escapeHtml(__($_limit)) ?>
<?php else: ?>
 <?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>
<?php endif; ?>

This usually happens when a value for the system configuration field "Allow All Products per Page" (catalog/frontend/list_allow_all) is selected as "yes"

Ref.: https://github.com/magento/magento2/commit/00fb26bfa86d302cf8ade46ca133b8b9c7f303d6#diff-f50afb0f7a81350c4dd383269f534abc0ce3acb99c431811fc94f7ebe13f68e4R26

answered Aug 8, 2022 at 6:44
1
  • 1
    This is still an issue on Magento ver. 2.4.5-p4 with "Allow All Products per Page" set to "yes". Fixed with your snippet in template template for limiter.phtml Commented Aug 29, 2023 at 15:43
0

The default template looks like this:

 <?php foreach ($block->getAvailableLimit() as $_key => $_limit):?>
 <option value="<?= $block->escapeHtmlAttr($_key) ?>"
 <?php if ($block->isLimitCurrent($_key)):?>
 selected="selected"
 <?php endif ?>>
 <?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>
 </option>
 <?php endforeach; ?>

this is line 26

<?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>

for some reason you have here $_limit as a translatable text insted a numerical value.
Check what the method $block->getAvailableLimit() returns. Make sure the re are translatable texts... You can also try to see what happens when you replace $_limit with $_limit->render()

answered Aug 5, 2022 at 14:11
2
  • Thanks, @Marjus for giving insight. Commented Aug 8, 2022 at 6:45
  • @Marius, I get this error immediately after upgrading Magento to 2.4.5. Can you share any insights into what might've caused this? Commented Sep 10, 2022 at 4:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.