-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Yes/No attribute value is not shown on a product details page #6634
Comments
Internal ticket created MAGETWO-59267. Thanks for reporting |
Yes/No Attributes are not visible on frontend due to error in the file -/Magento/Catalog/Block/Product/View/Attributes.php function getAdditionalData(array $excludeAttr = []) check if the attributes value is string but in case of Yes/No Attributes the value is something like this - object(Magento\Framework\Phrase)#2322 (2) { ["text":"Magento\Framework\Phrase":private]=> string(3) "Yes" ["arguments":"Magento\Framework\Phrase":private]=> array(0) { } } here is the check for string - if (is_string($value) && strlen($value)) { other attribute types are working fine for me. |
When will this be fixed? |
When will this be fixed. Has been open for a long time. |
This is our solution: Extend the condition for attributes that are instances of \Magento\Framework\Phrase.
|
@TKlement, fix idea looks good to me, maybe prepare a pull request? ;) |
Internal ticket to track issue progress: MAGETWO-65364 |
@TKlement The solution you outlined is close, but if you have a large number of custom attributes this will show any non-defined attributes for a product as "N/A". If you modify your solution slightly to this:
So instead of modifying the last if block in Magento\Catalog\Block\Product\View\Attributes->getAdditionalData() to allow objects of type Phrase, you instead add an additional elseif to the block before that to check for type Phrase and then set the value equal to $value->getText(). By doing this if the text value of the attribute is still empty, it will not be shown on the frontend of the site. |
Per the discussion here: magento#6634 I found when I implemented the proposed fix that was implemented in this file in my own Magento installation, all boolean attributes were returned even if they were not assigned to a product and had no value in the database. So my product pages were full of NULLs and had a large number of non-relevant attributes listed because of the large number of custom attributes we are utilizing for our product catalog. The small change I have made here allows attributes that have been assigned a value to be displayed, but non-relevant/unset attributes are not, therefore I feel it is a much cleaner solution to the problem.
@alexkuk, thank you for your report. |
The issue has been fixed and delivered to 2.2-develop branch. Will be available with upcoming patch release |
Sorry @okobchenko, this is not included in 2.2.2, right? |
MC-38769: PHPUnit 9 support for PHP 2.3.x
Preconditions
Steps to reproduce
Actual result
The More Information tab doesn't contain our newly created attribute.
Expected result
The More Information tab contains our newly created attribute.
Additional information
If I make some yes/no attribute visible on frontend, it doesn't appear in the More Information tab on a product details page. I debugged it and found that this relates to the fact that translated string are wrapped into the Phrase object: https://community.magento.com/t5/Magento-2-Feature-Requests-and/function-returns-Phrase-object-Could-this-return-string/idi-p/45075
Particularly, it's \Magento\Catalog\Block\Product\View\Attributes::getAdditionalData() - it requires $value to be string to be added to the $data array. In case of Yes/No attributes $value is an object of \Magento\Framework\Phrase.
The text was updated successfully, but these errors were encountered: