Skip to content

Commit 89d1b2c

Browse files
irenelagnoomiroshnichenko
authored andcommitted
MAGETWO-59626: Error saving configurable product after disabling child products
1 parent 3e2ef71 commit 89d1b2c

File tree

2 files changed

+38
-1
lines changed
  • app/code/Magento/Catalog

2 files changed

+38
-1
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ protected function createModel()
2424

2525
public function testModifyData()
2626
{
27-
$this->assertSame($this->getSampleData(), $this->getModel()->modifyData($this->getSampleData()));
27+
$this->productMock->expects($this->once())->method('getId')->willReturn(2051);
28+
$actualResult = $this->getModel()->modifyData($this->getSampleData());
29+
$this->assertSame("", $actualResult[2051]['product']['media_gallery']['images'][0]['label']);
2830
}
2931

3032
public function testModifyMeta()
@@ -40,4 +42,24 @@ public function testModifyMeta()
4042

4143
$this->assertSame([], $this->getModel()->modifyMeta($meta));
4244
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
protected function getSampleData()
50+
{
51+
return [
52+
2051 => [
53+
'product' => [
54+
'media_gallery' => [
55+
'images' => [
56+
[
57+
'label' => null
58+
]
59+
]
60+
]
61+
]
62+
]
63+
];
64+
}
4365
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Images.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public function modifyMeta(array $meta)
5151
*/
5252
public function modifyData(array $data)
5353
{
54+
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
55+
$product = $this->locator->getProduct();
56+
$modelId = $product->getId();
57+
if (
58+
isset($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery'])
59+
&& !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery'])
60+
&& !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'])
61+
) {
62+
foreach ($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'] as $index => $image) {
63+
if (!isset($image['label'])) {
64+
$data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'][$index]['label'] = "";
65+
}
66+
}
67+
};
68+
5469
return $data;
5570
}
5671
}

0 commit comments

Comments
 (0)