Skip to content
Snippets Groups Projects
Commit 21d58ef7 authored by aakimov's avatar aakimov
Browse files

MAGETWO-58338: Problem Adding Attribute Options that Start with a Number via REST API

parent 92f6a73c
No related merge requests found
...@@ -464,7 +464,8 @@ class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb ...@@ -464,7 +464,8 @@ class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{ {
$connection = $this->getConnection(); $connection = $this->getConnection();
$table = $this->getTable('eav_attribute_option'); $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 (!empty($option['delete'][$optionId])) {
if ($intOptionId) { if ($intOptionId) {
......
...@@ -50,8 +50,9 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract ...@@ -50,8 +50,9 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
/** /**
* @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php * @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'); $this->_markTestAsRestOnly('Fix inconsistencies in WSDL and Data interfaces');
$testAttributeCode = 'select_attribute'; $testAttributeCode = 'select_attribute';
...@@ -67,18 +68,6 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract ...@@ -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( $response = $this->_webApiCall(
$serviceInfo, $serviceInfo,
[ [
...@@ -96,6 +85,37 @@ class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract ...@@ -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 * @magentoApiDataFixture Magento/Catalog/Model/Product/Attribute/_files/select_attribute.php
*/ */
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment