Skip to content

Commit 21d58ef

Browse files
committed
MAGETWO-58338: Problem Adding Attribute Options that Start with a Number via REST API
1 parent 92f6a73 commit 21d58ef

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ protected function _updateAttributeOption($object, $optionId, $option)
464464
{
465465
$connection = $this->getConnection();
466466
$table = $this->getTable('eav_attribute_option');
467-
$intOptionId = (int)$optionId;
467+
// ignore strings that start with a number
468+
$intOptionId = is_numeric($optionId) ? (int)$optionId : 0;
468469

469470
if (!empty($option['delete'][$optionId])) {
470471
if ($intOptionId) {

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeOptionManagementInterfaceTest.php

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public function testGetItems()
5050

5151
/**
5252
* @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php
53+
* @dataProvider addDataProvider
5354
*/
54-
public function testAdd()
55+
public function testAdd($optionData)
5556
{
5657
$this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
5758
$testAttributeCode = 'select_attribute';
@@ -67,18 +68,6 @@ public function testAdd()
6768
],
6869
];
6970

70-
$optionData = [
71-
AttributeOptionInterface::LABEL => 'new color',
72-
AttributeOptionInterface::SORT_ORDER => 100,
73-
AttributeOptionInterface::IS_DEFAULT => true,
74-
AttributeOptionInterface::STORE_LABELS => [
75-
[
76-
AttributeOptionLabelInterface::LABEL => 'DE label',
77-
AttributeOptionLabelInterface::STORE_ID => 1,
78-
],
79-
],
80-
];
81-
8271
$response = $this->_webApiCall(
8372
$serviceInfo,
8473
[
@@ -96,6 +85,37 @@ public function testAdd()
9685
);
9786
}
9887

88+
/**
89+
* @return array
90+
*/
91+
public function addDataProvider()
92+
{
93+
$optionPayload = [
94+
AttributeOptionInterface::LABEL => 'new color',
95+
AttributeOptionInterface::SORT_ORDER => 100,
96+
AttributeOptionInterface::IS_DEFAULT => true,
97+
AttributeOptionInterface::STORE_LABELS => [
98+
[
99+
AttributeOptionLabelInterface::LABEL => 'DE label',
100+
AttributeOptionLabelInterface::STORE_ID => 1,
101+
],
102+
],
103+
];
104+
105+
return [
106+
'option_without_value_node' => [
107+
$optionPayload
108+
],
109+
'option_with_value_node_that_starts_with_text' => [
110+
array_merge($optionPayload , [AttributeOptionInterface::VALUE => 'some_text'])
111+
],
112+
'option_with_value_node_that_starts_with_a_number' => [
113+
array_merge($optionPayload , [AttributeOptionInterface::VALUE => '123_some_text'])
114+
],
115+
116+
];
117+
}
118+
99119
/**
100120
* @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php
101121
*/

0 commit comments

Comments
 (0)