Skip to content

Commit b9e0abe

Browse files
#8810 - Solved api functional test issue
1 parent fc00146 commit b9e0abe

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function add($entityType, $attributeCode, $option)
6969
try {
7070
$this->resourceModel->save($attribute);
7171
if ($optionLabel && $attribute->getAttributeCode()) {
72-
$option->setValue($attribute->getSource()->getOptionId($optionLabel));
72+
$this->setOptionValue($option, $attribute, $optionLabel);
7373
}
7474
} catch (\Exception $e) {
7575
throw new StateException(__('Cannot save attribute %1', $attributeCode));
@@ -151,4 +151,26 @@ private function getOptionId($option)
151151
{
152152
return $option->getValue() ?: 'new_option';
153153
}
154+
155+
/**
156+
* @param \Magento\Eav\Api\Data\AttributeOptionInterface $option
157+
* @param \Magento\Eav\Api\Data\AttributeInterface $attribute
158+
* @param string $optionLabel
159+
* @return void
160+
*/
161+
public function setOptionValue($option, $attribute, $optionLabel)
162+
{
163+
if ($optionId = $attribute->getSource()->getOptionId($optionLabel)) {
164+
$option->setValue($attribute->getSource()->getOptionId($optionId));
165+
} else {
166+
if (is_array($option->getStoreLabels())) {
167+
foreach ($option->getStoreLabels() as $label) {
168+
if ($optionId = $attribute->getSource()->getOptionId($label->getLabel())) {
169+
$option->setValue($attribute->getSource()->getOptionId($optionId));
170+
break;
171+
}
172+
}
173+
}
174+
}
175+
}
154176
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testAdd($optionData)
7474
]
7575
);
7676

77-
$this->assertTrue($response);
77+
$this->assertNotNull($response[AttributeOptionInterface::VALUE]);
7878
$updatedData = $this->getAttributeOptions($testAttributeCode);
7979
$lastOption = array_pop($updatedData);
8080
$this->assertEquals(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testAdd($optionData)
4242
]
4343
);
4444

45-
$this->assertTrue($response);
45+
$this->assertNotNull($response[AttributeOptionInterface::VALUE]);
4646
$updatedData = $this->getAttributeOptions($testAttributeCode);
4747
$lastOption = array_pop($updatedData);
4848
$this->assertEquals(

0 commit comments

Comments
 (0)