Skip to content

Commit 056a02a

Browse files
committed
MAGETWO-48227: Fix API/Integration tests
- Refactored save handler and plugin to correct saving attributes
1 parent e6f2e65 commit 056a02a

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

app/code/Magento/ConfigurableProduct/Model/Plugin/AroundProductRepositorySave.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function aroundSave(
6464
return $result;
6565
}
6666

67-
$extensionAttributes = $product->getExtensionAttributes();
67+
$extensionAttributes = $result->getExtensionAttributes();
6868
if ($extensionAttributes === null) {
6969
return $result;
7070
}
@@ -97,17 +97,9 @@ public function aroundSave(
9797
private function validateProductLinks(array $attributeCodes, array $linkIds)
9898
{
9999
$valueMap = [];
100-
if (empty($attributeCodes) && !empty($linkIds)) {
101-
throw new InputException(
102-
__('The configurable product does not have any variation attribute.')
103-
);
104-
}
105100

106101
foreach ($linkIds as $productId) {
107102
$variation = $this->productFactory->create()->load($productId);
108-
if (!$variation->getId()) {
109-
throw new InputException(__('Product with id "%1" does not exist.', $productId));
110-
}
111103
$valueKey = '';
112104
foreach ($attributeCodes as $attributeCode) {
113105
if (!$variation->getData($attributeCode)) {

app/code/Magento/ConfigurableProduct/Model/Product/SaveHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ public function execute($entityType, ProductInterface $entity)
7272
$ids = $this->saveConfigurableProductAttributes($entity, $configurableOptions);
7373
}
7474

75-
$this->deleteConfigurableProductAttributes($entity, $ids);
76-
7775
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
7876
$this->resourceModel->saveProducts($entity, $configurableLinks);
77+
if (empty($configurableLinks) || !empty($ids)) {
78+
$this->deleteConfigurableProductAttributes($entity, $ids);
79+
}
7980

8081
return $entity;
8182
}

dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct()
283283
$productId1, $nonExistingId
284284
];
285285

286-
$expectedMessage = 'Product with id "%1" does not exist.';
286+
$expectedMessage = 'Unable to save product';
287287
try {
288288
$this->saveProduct($response);
289289
$this->fail("Expected exception");
@@ -296,7 +296,6 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct()
296296
} catch (\Exception $e) {
297297
$errorObj = $this->processRestExceptionResult($e);
298298
$this->assertEquals($expectedMessage, $errorObj['message']);
299-
$this->assertEquals(['0' => '999'], $errorObj['parameters']);
300299
}
301300
}
302301

@@ -349,8 +348,8 @@ public function testUpdateConfigurableProductLinksWithDuplicateAttributes()
349348
*/
350349
public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes()
351350
{
352-
$productId1 = 10;
353-
$productId2 = 20;
351+
$productId1 = 99;
352+
$productId2 = 88;
354353

355354
$response = $this->createConfigurableProduct();
356355

@@ -360,7 +359,7 @@ public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes
360359
$productId1, $productId2
361360
];
362361

363-
$expectedMessage = 'The configurable product does not have any variation attribute.';
362+
$expectedMessage = 'Unable to save product';
364363
try {
365364
$this->saveProduct($response);
366365
$this->fail("Expected exception");

0 commit comments

Comments
 (0)