Skip to content

Commit 4b85f3a

Browse files
committed
MAGETWO-71289: No such entity exception is thrown when trying to create a Scheduled update for Product with custom option
- support option value recreation in case if we schedule new update
1 parent e19523d commit 4b85f3a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app/code/Magento/Catalog/Model/Product/Option/Repository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
172172
$originalValues = $persistedOption->getValues();
173173
$newValues = $option->getData('values');
174174
if ($newValues) {
175-
$newValues = $this->markRemovedValues($newValues, $originalValues);
175+
if (isset($originalValues)) {
176+
$newValues = $this->markRemovedValues($newValues, $originalValues);
177+
}
176178
$option->setData('values', $newValues);
177179
}
178180
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,29 @@ public function testSave()
267267
]);
268268
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
269269
}
270+
271+
public function testSaveWhenOptionTypeWasChanged()
272+
{
273+
$productSku = 'simple_product';
274+
$optionId = 1;
275+
$this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku);
276+
$this->productRepositoryMock
277+
->expects($this->once())
278+
->method('get')
279+
->with($productSku)
280+
->willReturn($this->productMock);
281+
$this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId);
282+
$this->productMock->expects($this->once())->method('getOptions')->willReturn([]);
283+
$this->optionMock->expects($this->once())->method('getData')->with('values')->willReturn([
284+
['option_type_id' => 4],
285+
['option_type_id' => 5]
286+
]);
287+
$optionCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Collection::class)
288+
->disableOriginalConstructor()
289+
->getMock();
290+
$optionCollection->expects($this->once())->method('getProductOptions')->willReturn([$this->optionMock]);
291+
$this->optionCollectionFactory->expects($this->once())->method('create')->willReturn($optionCollection);
292+
$this->optionMock->expects($this->once())->method('getValues')->willReturn(null);
293+
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
294+
}
270295
}

0 commit comments

Comments
 (0)