-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[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
Conversation
Hi @p-bystritsky, thanks for your contribution, we can start from processing this PR targeting
which was not running on Travis at that time. |
|
||
protected function setUp() | ||
{ | ||
// @codingStandardsIgnoreStart |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed them.
@orlangur can you please provide more information about requested changes? |
@p-bystritsky didn't check after last changes yet, Travis builds are green so I suppose it will be good to go. |
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
6533642
to
021070f
Compare
021070f
to
b3cbda2
Compare
…th value N/A or NO on storefront. #12057
@magento-engcom-team Are these changes safe for 2.1.x? Is there a backport in progress? If not, I'll take it. |
This is a backport for #10619
Description
Attributes with no value set should not display on storefront.
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist