From 21d58ef7b7af29ebfea183dbe5e4a084a5b2c343 Mon Sep 17 00:00:00 2001
From: aakimov <aakimov@magento.com>
Date: Thu, 15 Sep 2016 12:42:59 +0300
Subject: [PATCH] MAGETWO-58338: Problem Adding Attribute Options that Start
 with a Number via REST API

---
 .../Model/ResourceModel/Entity/Attribute.php  |  3 +-
 ...AttributeOptionManagementInterfaceTest.php | 46 +++++++++++++------
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php
index 19f332da4c5..ab269e8f1f7 100644
--- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php
+++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php
@@ -464,7 +464,8 @@ class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
     {
         $connection = $this->getConnection();
         $table = $this->getTable('eav_attribute_option');
-        $intOptionId = (int)$optionId;
+        // ignore strings that start with a number
+        $intOptionId = is_numeric($optionId) ? (int)$optionId : 0;
 
         if (!empty($option['delete'][$optionId])) {
             if ($intOptionId) {
diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeOptionManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeOptionManagementInterfaceTest.php
index cd8a43e5105..744b861e5d0 100644
--- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeOptionManagementInterfaceTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeOptionManagementInterfaceTest.php
@@ -50,8 +50,9 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
 
     /**
      * @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php
+     * @dataProvider addDataProvider
      */
-    public function testAdd()
+    public function testAdd($optionData)
     {
         $this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
         $testAttributeCode = 'select_attribute';
@@ -67,18 +68,6 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
             ],
         ];
 
-        $optionData = [
-            AttributeOptionInterface::LABEL => 'new color',
-            AttributeOptionInterface::SORT_ORDER => 100,
-            AttributeOptionInterface::IS_DEFAULT => true,
-            AttributeOptionInterface::STORE_LABELS => [
-                [
-                    AttributeOptionLabelInterface::LABEL => 'DE label',
-                    AttributeOptionLabelInterface::STORE_ID => 1,
-                ],
-            ],
-        ];
-
         $response = $this->_webApiCall(
             $serviceInfo,
             [
@@ -96,6 +85,37 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
         );
     }
 
+    /**
+     * @return array
+     */
+    public function addDataProvider()
+    {
+        $optionPayload = [
+            AttributeOptionInterface::LABEL => 'new color',
+            AttributeOptionInterface::SORT_ORDER => 100,
+            AttributeOptionInterface::IS_DEFAULT => true,
+            AttributeOptionInterface::STORE_LABELS => [
+                [
+                    AttributeOptionLabelInterface::LABEL => 'DE label',
+                    AttributeOptionLabelInterface::STORE_ID => 1,
+                ],
+            ],
+        ];
+
+        return [
+            'option_without_value_node' => [
+                $optionPayload
+            ],
+            'option_with_value_node_that_starts_with_text' => [
+                array_merge($optionPayload , [AttributeOptionInterface::VALUE => 'some_text'])
+            ],
+            'option_with_value_node_that_starts_with_a_number' => [
+                array_merge($optionPayload , [AttributeOptionInterface::VALUE => '123_some_text'])
+            ],
+
+        ];
+    }
+
     /**
      * @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php
      */
-- 
GitLab