Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 1df94b3

Browse files
MAGETWO-83171: Fix json encoded attribute backend type when attribute value is null #11947
2 parents d067c9c + 9758002 commit 1df94b3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Backend/JsonEncoded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function afterLoad($object)
5858
{
5959
parent::afterLoad($object);
6060
$attrCode = $this->getAttribute()->getAttributeCode();
61-
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode)));
61+
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode) ?: '{}'));
6262
return $this;
6363
}
6464
}

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Backend/JsonEncodedTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,18 @@ public function testAfterLoad()
9595
$this->model->afterLoad($product);
9696
$this->assertEquals([1, 2, 3], $product->getData('json_encoded'));
9797
}
98+
99+
/**
100+
* Test after load handler with null attribute value
101+
*/
102+
public function testAfterLoadWithNullAttributeValue()
103+
{
104+
$product = new \Magento\Framework\DataObject(
105+
[
106+
'json_encoded' => null
107+
]
108+
);
109+
$this->model->afterLoad($product);
110+
$this->assertEquals([], $product->getData('json_encoded'));
111+
}
98112
}

0 commit comments

Comments
 (0)