-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
getAttributeRawValue return false if value is '0' #572
getAttributeRawValue return false if value is '0' #572
Conversation
huh, thats a risky field to act on.
which then still leads to return false, and its returning false for null and In the end it still seems to lead to the expected result for any cases I can imagine. But I wonder if we should handle also the empty string case to return an empty string? This may also have a minimal impact on performance for some usecases. |
I think the problem is with the fact that one return statement deals with two cases: single attribute and multiple attributes. It is better to handle each separately. if (sizeof($attributesData) == 1) {
$_data = each($attributesData);
return $_data[1];
}
return $attributesData ? $attributesData : false; |
One simple example for understand the problems : with getAttributeRawValue you can't know if the real value is empty or 0. I think it's not a problem for the Core of Magento, but for custom devlopment (in my case ^^, for example, you need different process if value is empty or if value is 0) this 'issue' can cause trouble. |
More lite :) better ! |
Could reproduce with one of my modules ... I do nut use 0 value so it doesnt appeared. Bit oftopic ... Should we care about impact on other people code? If someone expects that I agree with a fix, but we should document it. (and maybe add unit tests for it). |
With 1.9.4.4 (after this PR) code changed from ...
to
@colinmollenhour did you verify that this change is still needed? |
To correct the last wrong commit.
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.
Tested. It now
Retrieve attribute's raw value from DB.
as originally intended. But note that int 0 becomes "0". It return null
if the value in DB is null
. If the attribute doesn't exist, it returns false
.
I consider it a bug and had to work around it in my projects several times. |
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.
tested, I don't know how we lived without this until now
I'm merging it and opening a new PR to document it in the README |
cherry-picked to v20 with no conflicts |
Something I think crazy
⁉️
When you call
Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'attribute', $storeId);
if the value is 0 in database (the real value), this function return FALSE (boolean)
Yes, for this function empty value and 0 return the same thing 'FALSE'.
I think It's more logic to return 0 if value is 0 (string or numeric). I know it's not a little update and can be affected many thing, but... 0 != false... No ?! :)