Skip to content

Commit f4a2ec5

Browse files
Yurii Hryhorievgemscng
authored andcommitted
MAGETWO-47698: [Github] Custom options not displayed correctly on a store view level magento#2908 magento#5885
- CR changes
1 parent d311d19 commit f4a2ec5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,16 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
144144
$option->setData('store_id', $product->getStoreId());
145145

146146
if ($option->getOptionId()) {
147-
if (!$product->getOptions()) {
148-
$product->getResource()->load($product, $product->getId());
147+
$options = $product->getOptions();
148+
if (!$options) {
149+
$options = $this->getProductOptions($product);
149150
}
150-
$persistedOption = $product->getOptionById($option->getOptionId());
151+
152+
$persistedOption = array_filter($options, function ($iOption) use ($option) {
153+
return $option->getOptionId() == $iOption->getOptionId();
154+
});
155+
$persistedOption = reset($persistedOption);
156+
151157
if (!$persistedOption) {
152158
throw new NoSuchEntityException();
153159
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,17 @@ public function testSaveNoSuchEntityException()
244244
{
245245
$productSku = 'simple_product';
246246
$optionId = 1;
247+
$productOptionId = 2;
247248
$this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku);
248249
$this->productRepositoryMock
249250
->expects($this->once())
250251
->method('get')
251252
->with($productSku)
252253
->willReturn($this->productMock);
254+
$productOption = clone $this->optionMock;
253255
$this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId);
254-
$this->productMock->expects($this->once())->method('getOptions')->willReturn(['some options']);
255-
$this->productMock->expects($this->once())->method('getOptionById')->with($optionId)->willReturn(null);
256+
$productOption->expects($this->any())->method('getOptionId')->willReturn($productOptionId);
257+
$this->productMock->expects($this->once())->method('getOptions')->willReturn([$productOption]);
256258
$this->optionRepository->save($this->optionMock);
257259
}
258260

0 commit comments

Comments
 (0)