-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fix json encoded attribute backend type when attribute value is null #11947
Conversation
@tkotosz could you cover your change with unit test in order to prevent regression in this part in future? |
Thanks for the PR @tkotosz I am happy with the code but I would love to see a test case to cover this. Currently the method |
@dmanners updated |
@@ -94,5 +94,13 @@ public function testAfterLoad() | |||
); | |||
$this->model->afterLoad($product); | |||
$this->assertEquals([1, 2, 3], $product->getData('json_encoded')); | |||
|
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.
Could you move this new code as separate method (test case)?
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.
@ihor-sviziev sure, done. Also I have squashed my commits.
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.
Add the visibility on the new test method please.
/** | ||
* Test after load handler with null attribute value | ||
*/ | ||
function testAfterLoadWithNullAttributeValue() |
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.
guess you also need to add the visibility on this method.
@dmanners fix pushed :) |
When you create a new product attribute with JsonEncoded backend type then you always get the following error when you try to load a product which doesn't have value for that specific attribute yet:
The source of the problem is this method:
When you do
json_decode(null, true)
, thenjson_last_error()
will return 4 (JSON_ERROR_SYNTAX
).With the suggested fix it will set the attribute value to empty array when the attribute value is null.