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()
3 Answers 3
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>
-
Unfortunately, the fix is not included in 2.4.5-p2 either. github.com/magento/magento2/blob/2.4.5-p2/app/code/Magento/…Densen– Densen2023年03月20日 12:31:36 +00:00Commented Mar 20, 2023 at 12:31
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"
-
1This 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.phtmlFlipmedia– Flipmedia2023年08月29日 15:43:27 +00:00Commented Aug 29, 2023 at 15:43
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()
-
Thanks, @Marjus for giving insight.sandip– sandip2022年08月08日 06:45:35 +00:00Commented 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?CodeForGood– CodeForGood2022年09月10日 04:25:36 +00:00Commented Sep 10, 2022 at 4:25
Explore related questions
See similar questions with these tags.