magento2: Fatal error on Product-Compare page when Short Description & Description attributes are empty

magento2-3-5-dev-bug t23dev-2020 05 17-21-40-01 (1)

Preconditions (*)

  1. Magento 2.3.5

Steps to reproduce (*)

  1. Add products to Compare where at least one product has no value set for at least one of its comparable attributes (e.g. “Description” or “Short Description” is empty).
  2. Go to the compare page (<site_root>/catalog/product_compare/index)

Expected result (*)

  1. Compare page should load normally, where any unconfigured attributes show “N/A” or “No”.

Actual result (*)

  1. Compare page is Broken and a Fatal Error is displayed. Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, object given in /app/web/vendor/magento/module-catalog/Helper/Output.php:245

Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, object given in /app/web/vendor/magento/module-catalog/Helper/Output.php:245 Stack trace: #0 /app/web/vendor/magento/module-catalog/Helper/Output.php(245): preg_match('/{{([a-z]{0,10}...', Object(Magento\Framework\Phrase)) #1 /app/web/vendor/magento/module-catalog/Helper/Output.php(185): Magento\Catalog\Helper\Output->isDirectivesExists(Object(Magento\Framework\Phrase)) #2 /app/web/vendor/magento/module-catalog/view/frontend/templates/product/compare/list.phtml(134): Magento\Catalog\Helper\Output->productAttribute(Object(Magento\Catalog\Model\Product\Interceptor), Object(Magento\Framework\Phrase), 'short_descripti...') #3 /app/web/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/app/web/vendor...') #4 /app/web/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\Compare\ListCompare\Interceptor), '/app/web/vendor...', Array) #5 /app/w in /app/web/vendor/magento/module-catalog/Helper/Output.php on line 245

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

I’m sorry, I did not notice that entry. If you like, I will remove my comments.

its ok with me friend and no problem. I just try to be thorough and right when doing bug reports and i was like, huh… but i reported that already what is he talking about?! 😃 Now lets quit small talk, and work on this and other issues. Have a nice day!

(Note that this is essentially the same issue as #20229, which was not fixed properly.)

Yes Brengineer, as you can see on the bottom of #20229 report, I have made an entry yesterday, but noone seem to re-open that case or take any action. So, I had to re-report it here, because although its about the same topic, its still not fixed, and I have no Idea why that report had been closed.

@operator888
This issue is already fixed on M2.4-develop Unfortunately we can not backlog our fixes on M.2.3.5 here the patch to apply on M2.3.5 https://github.com/CarmineDamore78/magento2/blob/bugfix-28254_fix_compare_page/0001-bugfix-28254-Fixed-issue-for-compare-page.patch

Hi.

Should be easy to solve. Add (string) before $attributeHtml. So Phrase is converted to string in preg_match().

    public function isDirectivesExists($attributeHtml)
.....
            if (preg_match($pattern, (string)$attributeHtml)) {
.....
    }

@magento fixed on M2.3.5

@magento I confirm the error on M2.3.5