diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php b/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php index 626d88f1acf82..53083d7168b45 100644 --- a/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php @@ -33,8 +33,10 @@ protected function processDeletedImages($product, array &$images) if (!empty($image['removed'])) { if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) { $recordsToDelete[] = $image['value_id']; - // only delete physical files if they are not used by any other products - if (!$this->resourceModel->countImageUses($image['file']) > 1) { + $catalogPath = $this->mediaConfig->getBaseMediaPath(); + $isFile = $this->mediaDirectory->isFile($catalogPath . $image['file']); + // only delete physical files if they are not used by any other products and if this file exist + if ($isFile && !($this->resourceModel->countImageUses($image['file']) > 1)) { $filesToDelete[] = ltrim($image['file'], '/'); } }