Skip to content

[Backport] magento/magento2#9961: Unused product attributes display with value N/A or NO on storefront. #12057

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

Merged
merged 4 commits into from
Dec 1, 2017

Conversation

p-bystritsky
Copy link
Contributor

This is a backport for #10619

Description

Attributes with no value set should not display on storefront.

Fixed Issues (if relevant)

  1. Unused product attributes display with value N/A or NO on storefront #9961: Unused product attributes display with value N/A or NO on storefront.
  2. Yes/No attribute value is not shown on a product details page #6634: Yes/No attribute value is not shown on a product details page

Manual testing scenarios

  1. Create a Custom Attribute, set it's "Catalog Input Type for Store Owner" to "Text Area" , "Visible on Catalog Pages on Storefront" to "Yes".
  2. Assign Custom Attribute to Default Attribute Set.
  3. Create a Custom Product with Default Attribute Set, make it visible on Storefront, do not set any value to Custom Attribute.
  4. Open Custom Product on Storefront - the Custom Attribute label and it's value should not be visible.
  5. Edit the Custom Product, set any value to it's Custom Attribute.
  6. Open Custom Product on Storefront - the Custom Attribute label and it's value should be visible.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@orlangur orlangur self-assigned this Nov 6, 2017
@orlangur
Copy link
Contributor

orlangur commented Nov 6, 2017

Hi @p-bystritsky, thanks for your contribution, we can start from processing this PR targeting 2.2-develop. The only problem in old PR was

2) Magento\Test\Integrity\Phrase\ArgumentsTest::testArguments
2 missed phrases were discovered: 
Missed Phrase: File: /home/travis/build/magento/magento2/app/code/Magento/Catalog/Test/Unit/Block/Product/View/AttributeTest.php 
Line: 68
Missed Phrase: File: /home/travis/build/magento/magento2/app/code/Magento/Catalog/Test/Unit/Block/Product/View/AttributeTest.php 
Line: 133
Failed asserting that an array is empty.

which was not running on Travis at that time.


protected function setUp()
{
// @codingStandardsIgnoreStart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of such annotations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them.

@magento-engcom-team magento-engcom-team added 2.2.x bugfix Component: Catalog Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 7, 2017
@p-bystritsky
Copy link
Contributor Author

@orlangur can you please provide more information about requested changes?

@orlangur
Copy link
Contributor

orlangur commented Nov 8, 2017

@p-bystritsky didn't check after last changes yet, Travis builds are green so I suppose it will be good to go.

Copy link

@vkublytskyi vkublytskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integrity tests are fixed now.

But I would like to ask you clean up the code and remove obsolete logic to improve code readability and make behavior more explicit. See my inline comments.

@@ -85,13 +85,15 @@ public function getAdditionalData(array $excludeAttr = [])

if (!$product->hasData($attribute->getAttributeCode())) {
$value = __('N/A');
} elseif ($value instanceof Phrase) {
$value = (string)$value;
} elseif ((string)$value == '') {
$value = __('No');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird logic. Why empty string should be transformed to No. Looks like this some obsolete workaround that should be removed. If this cause any issue then it definitely should be fixed in another way.
Please remove this elseif logic as it has no sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely this was used to display boolean attributes with Yes/No values.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur Yes/No values at this point already handled in \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::getValue. And this is dangerous to substitute empty value with "No" as empty value may appear for different reasons (e.g. empty text field, dropdown without selected item, etc.). Magento should rid of such code, decrease coupling between different classes and do not base implementation on current execution flow but build reusable components with high cohesion so changes in one system part will not cause bugs in another.

@@ -85,13 +85,15 @@ public function getAdditionalData(array $excludeAttr = [])

if (!$product->hasData($attribute->getAttributeCode())) {
$value = __('N/A');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also should remove this code as there are a lot of complaints about such behavior. This code was "dead" for a long time so everyone expects that not used attribute is ignored on storefront.
Please remove this if

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change system behavior in a way desired by Community without PO approval?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, behavior was changed when instanceof Phrase was added to if below. I can see that __('N/A') code was dead for a long time (including M1) so expectations in most Magento versions not used attributes are not displayed on a storefornt product page. Support also has multiple tickets to return previous behavior (not show N/A) back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I wan't aware about M1, and yes, such useful behavior was introduced accidentally in scope of another bugfix.


if ($value instanceof Phrase) {
$value = (string)$value;
} if ($attribute->getFrontendInput() == 'price' && is_string($value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if formatting looks pretty strange, should it be on next line or elseif? For the sake of cleanup === use would be nice also.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. should be elseif. Thanks

@okorshenko okorshenko merged commit b3cbda2 into magento:2.2-develop Dec 1, 2017
okorshenko pushed a commit that referenced this pull request Dec 1, 2017
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Dec 1, 2017
@Ctucker9233
Copy link

@magento-engcom-team Are these changes safe for 2.1.x? Is there a backport in progress? If not, I'll take it.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix 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 Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants