diff --git a/vendor/magento/module-catalog/Model/ProductRepository/MediaGalleryProcessor.php b/vendor/magento/module-catalog/Model/ProductRepository/MediaGalleryProcessor.php index b67cf4acd9f..031c7f7ae3e 100644 --- a/vendor/magento/module-catalog/Model/ProductRepository/MediaGalleryProcessor.php +++ b/vendor/magento/module-catalog/Model/ProductRepository/MediaGalleryProcessor.php @@ -82,6 +82,7 @@ class MediaGalleryProcessor * @throws InputException * @throws StateException * @throws LocalizedException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function processMediaGallery(ProductInterface $product, array $mediaGalleryEntries) :void { @@ -113,6 +114,9 @@ class MediaGalleryProcessor // phpcs:ignore Magento2.Performance.ForeachArrayMerge $existingMediaGallery[$key] = array_merge($existingEntry, $updatedEntry); } + } elseif (!empty($newEntries) && isset($existingEntry['value_id'])) { + //avoid deleting an exiting image while adding a new one + unset($existingMediaGallery[$key]); } elseif ($this->canRemoveImage($product, $existingEntry)) { //set the removed flag $existingEntry['removed'] = true;