Skip to content

Commit e132de9

Browse files
author
Yu Tang
committed
MAGETWO-28254: ConfigurableProduct Integration API
- Validate product links when there is no variation attribute
1 parent 3e428cf commit e132de9

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ protected function saveConfigurableProductLinks(
165165
protected function validateProductLinks(array $attributeCodes, array $linkIds)
166166
{
167167
$valueMap = [];
168+
if (empty($attributeCodes) && !empty($linkIds)) {
169+
throw new InputException(
170+
__('The configurable product does not have any variation attribute.')
171+
);
172+
}
173+
168174
foreach ($linkIds as $productId) {
169175
$variation = $this->productFactory->create()->load($productId);
170176
if (!$variation->getId()) {

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,31 @@ public function testAroundSaveWithLinksWithDuplicateAttributes()
413413
$this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock);
414414
}
415415

416+
/**
417+
* @expectedException \Magento\Framework\Exception\InputException
418+
* @expectedExceptionMessage The configurable product does not have any variation attribute.
419+
*/
420+
public function testAroundSaveWithLinksWithoutVariationAttributes()
421+
{
422+
$links = [4, 5];
423+
424+
$this->setupConfigurableProductAttributes([]);
425+
426+
$this->productMock->expects($this->once())->method('getTypeId')
427+
->willReturn(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
428+
$this->productMock->expects($this->once())
429+
->method('getExtensionAttributes')
430+
->willReturn($this->productExtensionMock);
431+
$this->productExtensionMock->expects($this->once())
432+
->method('getConfigurableProductOptions')
433+
->willReturn(null);
434+
$this->productExtensionMock->expects($this->once())
435+
->method('getConfigurableProductLinks')
436+
->willReturn($links);
437+
438+
$this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock);
439+
}
440+
416441
public function testAroundSaveWithOptions()
417442
{
418443
$productSku = "configurable_sku";

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,38 @@ public function testUpdateConfigurableProductLinksWithDuplicateAttributes()
352352
}
353353
}
354354

355+
/**
356+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
357+
*/
358+
public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes()
359+
{
360+
$productId1 = 10;
361+
$productId2 = 20;
362+
363+
$response = $this->createConfigurableProduct();
364+
365+
/** delete all variation attribute */
366+
$response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'] = [];
367+
$response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [
368+
$productId1, $productId2
369+
];
370+
371+
$expectedMessage = 'The configurable product does not have any variation attribute.';
372+
try {
373+
$this->saveProduct($response);
374+
$this->fail("Expected exception");
375+
} catch (\SoapFault $e) {
376+
$this->assertContains(
377+
$expectedMessage,
378+
$e->getMessage(),
379+
"SoapFault does not contain expected message."
380+
);
381+
} catch (\Exception $e) {
382+
$errorObj = $this->processRestExceptionResult($e);
383+
$this->assertEquals($expectedMessage, $errorObj['message']);
384+
}
385+
}
386+
355387
/**
356388
* Get product
357389
*

0 commit comments

Comments
 (0)