$ bin/magento cache:clean
$ bin/magento indexer:reindex
The More Information tab doesn't contain our newly created attribute.
The More Information tab contains our newly created attribute.
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.
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)) {
$data[$attribute->getAttributeCode()] = [
'label' => __($attribute->getStoreLabel()),
'value' => $value,
'code' => $attribute->getAttributeCode(),
];
}
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.
use Magento\Framework\Phrase;
...
if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
$data[$attribute->getAttributeCode()] = [
'label' => __($attribute->getStoreLabel()),
'value' => $value,
'code' => $attribute->getAttributeCode(),
];
}
@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:
use Magento\Framework\Phrase;
...
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = $this->priceCurrency->convertAndFormat($value);
} elseif ($value instanceof Phrase) {
$value = $value->getText();
}
if (is_string($value) && strlen($value)) {
...
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.
@alexkuk, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0-dev, 2.2.0, 2.1.9
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?