Skip to content

Commit 58d1338

Browse files
Chhandak.Baruadevarul
authored andcommitted
ACP2E-1479: Product with any custom option causes an error when deleting product images
1 parent 8b1deba commit 58d1338

File tree

1 file changed

+8
-1
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product

1 file changed

+8
-1
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,23 @@ private function handleImageRemoveError($postData, $productId)
223223
{
224224
if (isset($postData['product']['media_gallery']['images'])) {
225225
$removedImagesAmount = 0;
226+
$removedImages = [];
226227
foreach ($postData['product']['media_gallery']['images'] as $image) {
227228
if (!empty($image['removed'])) {
228229
$removedImagesAmount++;
230+
$removedImages[] = $image['value_id'];
229231
}
230232
}
231233
if ($removedImagesAmount) {
232234
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
233235
$product = $this->productRepository->getById($productId);
234236
$images = $product->getMediaGallery('images');
235-
if (is_array($images) && $expectedImagesAmount >= count($images)) {
237+
foreach ($images as $key => $imageItem) {
238+
if (in_array($imageItem['value_id'], $removedImages)) {
239+
unset($images[$key]);
240+
}
241+
}
242+
if (is_array($images) && $expectedImagesAmount != count($images)) {
236243
$this->messageManager->addNoticeMessage(
237244
__('The image cannot be removed as it has been assigned to the other image role')
238245
);

0 commit comments

Comments
 (0)