Skip to content

Commit f927dba

Browse files
authored
ENGCOM-4735: Add multibyte support for attributeSource getOptionId method #22033
2 parents 4ee30df + 8d0cfe3 commit f927dba

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Eav\Model\Entity\Attribute\Source;
78

89
/**
@@ -65,7 +66,7 @@ public function getOptionText($value)
6566
{
6667
$options = $this->getAllOptions();
6768
// Fixed for tax_class_id and custom_design
68-
if (sizeof($options) > 0) {
69+
if (count($options) > 0) {
6970
foreach ($options as $option) {
7071
if (isset($option['value']) && $option['value'] == $value) {
7172
return isset($option['label']) ? $option['label'] : $option['value'];
@@ -88,7 +89,7 @@ public function getOptionText($value)
8889
public function getOptionId($value)
8990
{
9091
foreach ($this->getAllOptions() as $option) {
91-
if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
92+
if ($this->mbStrcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
9293
return $option['value'];
9394
}
9495
}
@@ -166,4 +167,20 @@ public function toOptionArray()
166167
{
167168
return $this->getAllOptions();
168169
}
170+
171+
/**
172+
* Multibyte support strcasecmp function version.
173+
*
174+
* @param string $str1
175+
* @param string $str2
176+
* @return int
177+
*/
178+
private function mbStrcasecmp($str1, $str2)
179+
{
180+
$encoding = mb_internal_encoding();
181+
return strcmp(
182+
mb_strtoupper($str1, $encoding),
183+
mb_strtoupper($str2, $encoding)
184+
);
185+
}
169186
}

0 commit comments

Comments
 (0)