Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error on product-compare page when attributes not configured #20229

Closed
Brengineer opened this issue Jan 11, 2019 · 16 comments
Closed

Fatal error on product-compare page when attributes not configured #20229

Brengineer opened this issue Jan 11, 2019 · 16 comments
Labels
Component: Catalog Fixed in 2.3.x The issue has been fixed in 2.3 release line good first issue Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@Brengineer
Copy link

Brengineer commented Jan 11, 2019

Preconditions

  1. Magento 2.3.x

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" 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. "Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, object given in [site_root]/vendor/magento/module-catalog/Helper/Output.php on line 229"

The error occurs in the isDirectivesExists() method, which expects a string param. This method is called by productAttribute(), which passes $attributeHtml, which it receives as a param that is also expected to be a string.
The issue is that in app/code/Magento/Catalog/view/frontend/templates/product/compare/list.phtml:119, where productAttribute() is called, the 2nd param passed is a value from \Magento\Catalog\Block\Product\Compare\ListCompare::getProductAttributeValue, which returns a \Magento\Framework\Phrase object when the value of an attribute is undefined. Therefore, an error is thrown when this object is passed through to preg_match().
The issue was triggered in commit #bdcfbc8, where a call to isDirectivesExists() is added to line 167 of app/code/Magento/Catalog/Helper/Output.php. However, this is reasonable, since a string is expected. Therefore I recommend simply modifying line 119 of list.phtml to cast the result of getProductAttributeValue() as a string, which would be appropriate, since that's what productAttribute() is expecting.

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 11, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Jan 11, 2019

Hi @Brengineer. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@Brengineer do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Jan 11, 2019

Hi @irajneeshgupta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@irajneeshgupta irajneeshgupta added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Component: Catalog Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Component: Catalog Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Jan 11, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jan 11, 2019
@magento-engcom-team
Copy link
Contributor

@irajneeshgupta Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97584 were created

@saphaljha saphaljha self-assigned this Jan 12, 2019
@magento-engcom-team
Copy link
Contributor

Hi @saphaljha. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

vivekkumarcedcoss added a commit to vivekkumarcedcoss/magento2 that referenced this issue Jan 12, 2019
@saphaljha saphaljha removed their assignment Jan 12, 2019
vivekkumarcedcoss added a commit to vivekkumarcedcoss/magento2 that referenced this issue Jan 15, 2019
@beejhuff
Copy link

beejhuff commented Jan 15, 2019

I have a project on 2.3.0 that is experiencing the same issue. We've reported the issue to Magento Partner Support and I'll be working with our developer team later this evening to implement the fix committed in the updated list.phtml file and verify if it resolves our reported issue as well.

@magento-engcom-team
Copy link
Contributor

Hi @Brengineer. Thank you for your report.
The issue has been fixed in #20231 by @vivekkumarcedcoss in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jan 26, 2019
magento-engcom-team added a commit that referenced this issue Jan 26, 2019
…ibutes not configured #20231

 - Merge Pull Request #20231 from vivekkumarcedcoss/magento2:vivekkumarcedcoss-issue-20229
 - Merged commits:
   1. db0e8b2
amol2jcommerce pushed a commit to amol2jcommerce/magento2 that referenced this issue Jan 27, 2019
amol2jcommerce pushed a commit to amol2jcommerce/magento2 that referenced this issue Jan 27, 2019
[Backport]  Fix magento#20229-Fatal error on product-compare page when attributes not configured
vivekkumarcedcoss added a commit to vivekkumarcedcoss/magento2 that referenced this issue Feb 2, 2019
@0-Sony
Copy link

0-Sony commented Mar 12, 2019

@magento-engcom-team give me 2.3.0 instance

@magento-engcom-team
Copy link
Contributor

Hi @0-Sony. Thank you for your request. I'm working on Magento 2.3.0 instance for you

@magento-engcom-team
Copy link
Contributor

Hi @0-Sony, here is your Magento instance.
Admin access: https://i-20229-2-3-0.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@Mohammed8960
Copy link

the bug still not fixed in 2.3

@WesleyVestjens
Copy link

the bug still not fixed in 2.3

2.3.0 or 2.3.1? The fix should be available in 2.3.1

@mverstraete
Copy link

Adding the is_string check in app/code/Magento/Catalog/view/frontend/templates/product/compare/list.phtml now causes some attribute values to not render at all.

For example, in the case of boolean attributes, \Magento\Catalog\Block\Product\Compare\ListCompare::getProductAttributeValue returns a \Magento\Framework\Phrase object, with the values of either "Yes" or "No". These values are now no longer rendered.

@Brengineer
Copy link
Author

Brengineer commented Feb 14, 2020

Yes, I agree. I did not like the given fix either. This is why I suggested in the first place to "cast the result... as a string". It is quite simple, and this way it is always rendered, but it will not cause any errors:

<?= /* @escapeNotVerified */ $helper->productAttribute($item, (string) $block->getProductAttributeValue($item, $attribute), $attribute->getAttributeCode()) ?>

Of course, to make the code a little cleaner, you could first set a variable:

<?php $attributeValueString = (string) $block->getProductAttributeValue($item, $attribute); ?>
<?= /* @escapeNotVerified */ $helper->productAttribute($item, $attributeValueString, $attribute->getAttributeCode()) ?>

@operator888
Copy link
Member

operator888 commented May 17, 2020

Hello,
This bug is still present at version 2.3.5

If you add 1 or more products in the Compare List, and these Products have no Short Description or Description, then when you visit the Compare page you get the following Fatal Error:

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

Update:
Since this BugReport is closed and nobody answered anything so far, I made a new Bug Report here: #28254

@gh-darvishani
Copy link

it is mg 2.3.5 p1 but I am still facing this issue

@Daniel-Khalily-3linc
Copy link

Daniel-Khalily-3linc commented Sep 9, 2020

/var/www/magento/vendor/magento/module-catalog/Helper/Output.php is failing because when the description isn't present, it's a Phrase Object and not a string. Casting to (string) fixes it.

Magento\Framework\Phrase Object
(
[text:Magento\Framework\Phrase:private] => N/A
[arguments:Magento\Framework\Phrase:private] => Array
(
)
)

Here's my patchfile for 2.3.5-p1
patchfile.txt

Looking at the current source I do see this is fixed in latest versions, and #28254 referenced above also indicates this.

P.S. (Not sure how I unassigned @irajneeshgupta , sorry about that if it's an issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Fixed in 2.3.x The issue has been fixed in 2.3 release line good first issue Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests