Skip to content

Commit ae0678e

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

File tree

1 file changed

+3
-9
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product

1 file changed

+3
-9
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function execute()
141141
$originalSku = $product->getSku();
142142
$canSaveCustomOptions = $product->getCanSaveCustomOptions();
143143
$product->save();
144+
144145
$this->handleImageRemoveError($data, $product->getId());
145146
$productId = $product->getEntityId();
146147
$productAttributeSetId = $product->getAttributeSetId();
@@ -213,7 +214,7 @@ public function execute()
213214
/**
214215
* Notify customer when image was not deleted in specific case.
215216
*
216-
* TODO: temporary workaround must be eliminated in MAGETWO-45306
217+
* TODO: temporary workaround must be eliminated in MAGETNO-45306
217218
*
218219
* @param array $postData
219220
* @param int $productId
@@ -223,22 +224,15 @@ private function handleImageRemoveError($postData, $productId)
223224
{
224225
if (isset($postData['product']['media_gallery']['images'])) {
225226
$removedImagesAmount = 0;
226-
$removedImages = [];
227227
foreach ($postData['product']['media_gallery']['images'] as $image) {
228228
if (!empty($image['removed'])) {
229229
$removedImagesAmount++;
230-
$removedImages[] = $image['value_id'];
231230
}
232231
}
233232
if ($removedImagesAmount) {
234233
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
235-
$product = $this->productRepository->getById($productId);
234+
$product = $this->productRepository->getById($productId, false, null, true);
236235
$images = $product->getMediaGallery('images');
237-
foreach ($images as $key => $imageItem) {
238-
if (in_array($imageItem['value_id'], $removedImages)) {
239-
unset($images[$key]);
240-
}
241-
}
242236
if (is_array($images) && $expectedImagesAmount != count($images)) {
243237
$this->messageManager->addNoticeMessage(
244238
__('The image cannot be removed as it has been assigned to the other image role')

0 commit comments

Comments
 (0)