Skip to content

Commit 59b2840

Browse files
committed
31870: updated the return type as void
1 parent 9ff747f commit 59b2840

File tree

2 files changed

+19
-77
lines changed

2 files changed

+19
-77
lines changed

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

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
* @param ProductRepositoryInterface $subject
5050
* @param ProductInterface $product
5151
* @param bool $saveOptions
52-
* @return array
52+
* @return void
5353
* @throws InputException
5454
* @throws NoSuchEntityException
5555
*
@@ -59,34 +59,24 @@ public function beforeSave(
5959
ProductRepositoryInterface $subject,
6060
ProductInterface $product,
6161
$saveOptions = false
62-
): array {
63-
$result = [$product, $saveOptions];
64-
if ($product->getTypeId() !== Configurable::TYPE_CODE) {
65-
return $result;
66-
}
67-
68-
$extensionAttributes = $product->getExtensionAttributes();
69-
if ($extensionAttributes === null) {
70-
return $result;
71-
}
72-
73-
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
74-
$configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
62+
): void {
63+
if ($product->getTypeId() === Configurable::TYPE_CODE
64+
&& null !== ($extensionAttributes = $product->getExtensionAttributes())
65+
) {
66+
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
67+
$configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
7568

76-
if (empty($configurableLinks) && empty($configurableOptions)) {
77-
return $result;
78-
}
79-
80-
$attributeCodes = [];
81-
/** @var OptionInterface $configurableOption */
82-
foreach ($configurableOptions as $configurableOption) {
83-
$eavAttribute = $this->productAttributeRepository->get($configurableOption->getAttributeId());
84-
$attributeCode = $eavAttribute->getAttributeCode();
85-
$attributeCodes[] = $attributeCode;
69+
if (!empty($configurableLinks) && !empty($configurableOptions)) {
70+
$attributeCodes = [];
71+
/** @var OptionInterface $configurableOption */
72+
foreach ($configurableOptions as $configurableOption) {
73+
$eavAttribute = $this->productAttributeRepository->get($configurableOption->getAttributeId());
74+
$attributeCode = $eavAttribute->getAttributeCode();
75+
$attributeCodes[] = $attributeCode;
76+
}
77+
$this->validateProductLinks($attributeCodes, $configurableLinks);
78+
}
8679
}
87-
$this->validateProductLinks($attributeCodes, $configurableLinks);
88-
89-
return $result;
9080
}
9181

9282
/**

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

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ public function testBeforeSaveWhenProductIsSimple(): void
119119
$this->product->expects(static::never())
120120
->method('getExtensionAttributes');
121121

122-
$this->assertEquals(
123-
$this->product,
124-
$this->plugin->beforeSave($this->productRepository, $this->product)[0]
125-
);
122+
$this->assertNull($this->plugin->beforeSave($this->productRepository, $this->product));
126123
}
127124

128125
/**
@@ -150,52 +147,7 @@ public function testBeforeSaveWithoutOptions(): void
150147
$this->productAttributeRepository->expects(static::never())
151148
->method('get');
152149

153-
$this->assertEquals(
154-
$this->product,
155-
$this->plugin->beforeSave($this->productRepository, $this->product)[0]
156-
);
157-
}
158-
159-
/**
160-
* Test saving a configurable product with same set of attribute values
161-
*
162-
* @return void
163-
*/
164-
public function testBeforeSaveWithLinks(): void
165-
{
166-
$this->expectException(InputException::class);
167-
$this->expectExceptionMessage('Products "5" and "4" have the same set of attribute values.');
168-
$links = [4, 5];
169-
$this->product->expects(static::once())
170-
->method('getTypeId')
171-
->willReturn(Configurable::TYPE_CODE);
172-
173-
$this->product->expects(static::once())
174-
->method('getExtensionAttributes')
175-
->willReturn($this->extensionAttributes);
176-
$this->extensionAttributes->expects(static::once())
177-
->method('getConfigurableProductOptions')
178-
->willReturn(null);
179-
$this->extensionAttributes->expects(static::once())
180-
->method('getConfigurableProductLinks')
181-
->willReturn($links);
182-
183-
$this->productAttributeRepository->expects(static::never())
184-
->method('get');
185-
186-
$product = $this->getMockBuilder(Product::class)
187-
->disableOriginalConstructor()
188-
->setMethods(['getData'])
189-
->getMock();
190-
191-
$this->productRepository->expects(static::exactly(2))
192-
->method('getById')
193-
->willReturn($product);
194-
195-
$product->expects(static::never())
196-
->method('getData');
197-
198-
$this->plugin->beforeSave($this->productRepository, $this->product);
150+
$this->assertNull($this->plugin->beforeSave($this->productRepository, $this->product));
199151
}
200152

201153
/**

0 commit comments

Comments
 (0)