Skip to content

Commit c119c82

Browse files
Peter SchwabAnna Bukatar
authored andcommitted
Don't filter non numeric values
1 parent f8474ca commit c119c82

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public function validate($object)
5858

5959
/**
6060
* Prepare attribute values
61-
*
62-
* @param array $data
63-
* @return string
6461
*/
6562
private function prepare(array $data): string
6663
{
67-
return implode(',', array_filter(array_unique($data), 'is_numeric'));
64+
return implode(
65+
',',
66+
array_filter(
67+
array_unique($data),
68+
fn($value) => is_numeric($value) || !empty($value))
69+
);
6870
}
6971
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ public static function validateDataProvider(): array
8787
['sku' => 'test1', 'attr' => '0,1,2,3,4'],
8888
true,
8989
'0,1,2,3,4'
90+
],
91+
'keeps non numeric values from string' => [
92+
['sku' => 'test1', 'attr' => 'foo,bar'],
93+
true,
94+
'foo,bar'
95+
],
96+
'keeps non numeric values from array' => [
97+
['sku' => 'test1', 'attr' => ['foo','bar']],
98+
true,
99+
'foo,bar'
100+
],
101+
'filters empty values from string' => [
102+
['sku' => 'test1', 'attr' => 'foo,bar,,123'],
103+
true,
104+
'foo,bar,123'
105+
],
106+
'filters empty values from array' => [
107+
['sku' => 'test1', 'attr' => ['foo','bar','',null,123]],
108+
true,
109+
'foo,bar,123'
90110
]
91111
];
92112
}

0 commit comments

Comments
 (0)