From c7e1defe63e859c2a1e19bcf736234533b3fa21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Me=CC=81ndez=20Calzada?= Date: Fri, 29 Mar 2019 14:18:26 +0100 Subject: [PATCH 1/3] Add multibyte support for attributeSource getOptionId method --- .../Attribute/Source/AbstractSource.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php index 36ad026029056..0e547e0887c30 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php @@ -88,7 +88,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']; } } @@ -166,4 +166,22 @@ public function toOptionArray() { return $this->getAllOptions(); } + + /** + * Multibyte support strcasecmp function version + * @param string $str1 + * @param string $str2 + * @param null|string $encoding + * @return int|\\lt + */ + private function mbStrcasecmp($str1, $str2, $encoding = null) + { + if (null === $encoding) { + $encoding = mb_internal_encoding(); + } + return strcmp( + mb_strtoupper($str1, $encoding), + mb_strtoupper($str2, $encoding) + ); + } } From d061c5461a316a44b6cc9b7a48c35aaff98b9719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Me=CC=81ndez=20Calzada?= Date: Tue, 9 Apr 2019 11:17:42 +0200 Subject: [PATCH 2/3] drop optional unused parameter --- .../Eav/Model/Entity/Attribute/Source/AbstractSource.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php index 0e547e0887c30..b291b7b28d5b7 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php @@ -171,14 +171,11 @@ public function toOptionArray() * Multibyte support strcasecmp function version * @param string $str1 * @param string $str2 - * @param null|string $encoding * @return int|\\lt */ - private function mbStrcasecmp($str1, $str2, $encoding = null) + private function mbStrcasecmp($str1, $str2) { - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } + $encoding = mb_internal_encoding(); return strcmp( mb_strtoupper($str1, $encoding), mb_strtoupper($str2, $encoding) From a168a3e1a618c967314fc27a556303530dfd2c26 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Fri, 19 Apr 2019 13:57:01 +0300 Subject: [PATCH 3/3] Fix static tests. --- .../Eav/Model/Entity/Attribute/Source/AbstractSource.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php index b291b7b28d5b7..a81d437acea36 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/AbstractSource.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Eav\Model\Entity\Attribute\Source; /** @@ -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']; @@ -168,10 +169,11 @@ public function toOptionArray() } /** - * Multibyte support strcasecmp function version + * Multibyte support strcasecmp function version. + * * @param string $str1 * @param string $str2 - * @return int|\\lt + * @return int */ private function mbStrcasecmp($str1, $str2) {