Skip to content

Commit 0a27f9c

Browse files
committed
magento/magento2#87588: Fix json encoded attribute backend type to not encode attribute value multiple times magento#13551
1 parent e6561ac commit 0a27f9c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function beforeSave($object)
4141
{
4242
// parent::beforeSave() is not called intentionally
4343
$attrCode = $this->getAttribute()->getAttributeCode();
44-
if ($object->hasData($attrCode) && !$this->isJsonEncoded((string)$object->getData($attrCode))) {
44+
if ($object->hasData($attrCode) && !$this->isJsonEncoded($object->getData($attrCode))) {
4545
$object->setData($attrCode, $this->jsonSerializer->serialize($object->getData($attrCode)));
4646
}
4747
return $this;
@@ -65,16 +65,18 @@ public function afterLoad($object)
6565
/**
6666
* Returns true if given param is a valid json value else false.
6767
*
68-
* @param string $value
68+
* @param $value
6969
* @return bool
7070
*/
71-
private function isJsonEncoded(string $value): bool
71+
private function isJsonEncoded($value): bool
7272
{
73-
$result = true;
74-
try {
75-
$this->jsonSerializer->unserialize($value);
76-
} catch (\InvalidArgumentException $e) {
77-
$result = false;
73+
$result = is_string($value);
74+
if ($result) {
75+
try {
76+
$this->jsonSerializer->unserialize($value);
77+
} catch (\InvalidArgumentException $e) {
78+
$result = false;
79+
}
7880
}
7981

8082
return $result;

0 commit comments

Comments
 (0)