diff --git a/Api/CalculatorInterface.php b/Api/CalculatorInterface.php deleted file mode 100644 index b953676..0000000 --- a/Api/CalculatorInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -getSource()->getOptionId($label) !== null) { + + $optionIdByLabel = $this->getOptionIdByLabel($attribute->getSource(), $label); + if ($optionIdByLabel !== null) { throw new InputException( __( 'Admin store attribute option label "%1" is already exists.', @@ -70,6 +71,39 @@ public function add($entityType, $attributeCode, $option) return $this->retrieveOptionId($attribute, $option); } + /** + * Get option id by label + * + * @param $attribute + * @param string $label + * @return null|string + */ + public function getOptionIdByLabel($attribute, $label) + { + foreach ($attribute->getAllOptions() as $option) { + if ($this->mbStrcasecmp($option['label'], $label) == 0) { + return $option['value']; + } + } + return null; + } + + /** + * 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) + ); + } + /** * Save attribute option * diff --git a/composer.json b/composer.json index 68a6dff..ded40c7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name" : "cobbyio/cobby-connector-magento2", "description" : "This extension for Magento 2 provides a direct integration of the cobby management methods to your Magento 2 shop.", - "version" : "2.4.8", + "version" : "2.4.9", "type" : "magento2-module", "require": { "magento/framework": "^102.0|^103.0|^104.0",