Skip to content

Commit

Permalink
ENGCOM-4735: Add multibyte support for attributeSource getOptionId me…
Browse files Browse the repository at this point in the history
…thod #22033
  • Loading branch information
sivaschenko authored Apr 23, 2019
2 parents 4ee30df + 8d0cfe3 commit f927dba
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Eav\Model\Entity\Attribute\Source;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ public function getOptionText($value)
{
$options = $this->getAllOptions();
// Fixed for tax_class_id and custom_design
if (sizeof($options) > 0) {
if (count($options) > 0) {
foreach ($options as $option) {
if (isset($option['value']) && $option['value'] == $value) {
return isset($option['label']) ? $option['label'] : $option['value'];
Expand All @@ -88,7 +89,7 @@ public function getOptionText($value)
public function getOptionId($value)
{
foreach ($this->getAllOptions() as $option) {
if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
if ($this->mbStrcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
return $option['value'];
}
}
Expand Down Expand Up @@ -166,4 +167,20 @@ public function toOptionArray()
{
return $this->getAllOptions();
}

/**
* Multibyte support strcasecmp function version.
*
* @param string $str1
* @param string $str2
* @return int
*/
private function mbStrcasecmp($str1, $str2)
{
$encoding = mb_internal_encoding();
return strcmp(
mb_strtoupper($str1, $encoding),
mb_strtoupper($str2, $encoding)
);
}
}

0 comments on commit f927dba

Please sign in to comment.