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

Yes/No attribute value is not shown on a product details page #6634

Closed
alexkuk opened this issue Sep 16, 2016 · 11 comments
Closed

Yes/No attribute value is not shown on a product details page #6634

alexkuk opened this issue Sep 16, 2016 · 11 comments
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 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

Comments

@alexkuk
Copy link

alexkuk commented Sep 16, 2016

Preconditions

  • Magento CE 2.1.1 with sample data (Luma theme).

Steps to reproduce

  1. Navigate to the backend.
  2. Go to Stores -> Attributes -> Product
  3. Click on the Add New Attribute button
  4. Set "Catalog Input Type for Store Owner" = Yes/No, set "Visible on Catalog Pages on Storefront" = Yes, and fill other required fields.
  5. Click Save Attribute button
  6. Go to Products -> Catalog. Click on some product that is visible on storefront.
  7. Find the newly created attribute field and fill it with Yes or No value. Save product.
  8. Clean cache and reindex:
$ bin/magento cache:clean
$ bin/magento indexer:reindex
  1. Open a storefront product page.

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.

@sevos1984
Copy link
Contributor

Internal ticket created MAGETWO-59267. Thanks for reporting

@sevos1984 sevos1984 added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Oct 3, 2016
@dinkeronline
Copy link

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.

@csdougliss
Copy link
Contributor

When will this be fixed?

@martijnhovinga
Copy link

When will this be fixed. Has been open for a long time.

@TKlement
Copy link

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(),
    ];
}

@orlangur
Copy link
Contributor

@TKlement, fix idea looks good to me, maybe prepare a pull request? ;)

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-65364

@usesi-jlambert
Copy link
Contributor

usesi-jlambert commented Aug 1, 2017

@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.

usesi-jlambert added a commit to usesi-jlambert/magento2 that referenced this issue Sep 5, 2017
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.
@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 9, 2017
@magento-engcom-team
Copy link
Contributor

@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

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Oct 9, 2017
@okorshenko okorshenko added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Nov 30, 2017
@okorshenko
Copy link
Contributor

The issue has been fixed and delivered to 2.2-develop branch. Will be available with upcoming patch release

@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 1, 2017
@oviliz
Copy link

oviliz commented Dec 19, 2017

Sorry @okobchenko, this is not included in 2.2.2, right?

mmansoor-magento pushed a commit that referenced this issue May 11, 2021
MC-38769: PHPUnit 9 support for PHP 2.3.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 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
Projects
None yet
Development

No branches or pull requests