From ab63d6ae1c795484410d441064fdaaba269532cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mateos?= Date: Fri, 29 Sep 2017 20:17:41 +0200 Subject: [PATCH] Fix the correct removal of the images and the removal of all images in the catalog. --- .../Magento/Catalog/Model/Product/Gallery/UpdateHandler.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php b/app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php index 626d88f1acf82..0dbad386f8b2f 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 exists + if (!($this->resourceModel->countImageUses($image['file']) > 1) && $isFile) { $filesToDelete[] = ltrim($image['file'], '/'); } }