Skip to content

Commit a8892e7

Browse files
committed
ACP2E-2093: Issue when uploading image with the same name while deleting the old image
- Fixed the original image when click on thumbnail image in PDP page.
1 parent 04b5602 commit a8892e7

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

app/code/Magento/Catalog/Model/Product/Image/RemoveDeletedImagesFromCache.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,33 @@ public function __construct(
8888
public function removeDeletedImagesFromCache(array $files)
8989
{
9090
if (count($files) > 0) {
91-
$imageArguments = $this->presentationConfig
91+
$images = $this->presentationConfig
9292
->getViewConfig(['area' => \Magento\Framework\App\Area::AREA_FRONTEND])
93-
->getMediaAttributes(
93+
->getMediaEntities(
9494
'Magento_Catalog',
95-
Image::MEDIA_TYPE_CONFIG_NODE,
96-
'product_page_image_small'
95+
Image::MEDIA_TYPE_CONFIG_NODE
9796
);
9897

99-
$imageMiscParams = $this->imageParamsBuilder->build($imageArguments);
98+
foreach ($images as $imageData) {
99+
$imageMiscParams = $this->imageParamsBuilder->build($imageData);
100100

101-
if (isset($imageMiscParams['image_type'])) {
102-
unset($imageMiscParams['image_type']);
103-
}
101+
if (isset($imageMiscParams['image_type'])) {
102+
unset($imageMiscParams['image_type']);
103+
}
104104

105-
$cacheId = $this->encryptor->hash(
106-
implode('_', $this->convertImageMiscParamsToReadableFormat
107-
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
108-
Encryptor::HASH_VERSION_MD5
109-
);
105+
$cacheId = $this->encryptor->hash(
106+
implode('_', $this->convertImageMiscParamsToReadableFormat
107+
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
108+
Encryptor::HASH_VERSION_MD5
109+
);
110110

111-
$catalogPath = $this->mediaConfig->getBaseMediaPath();
111+
$catalogPath = $this->mediaConfig->getBaseMediaPath();
112112

113-
foreach ($files as $filePath) {
114-
$this->mediaDirectory->delete(
115-
$catalogPath . '/cache/' . $cacheId . '/' . $filePath
116-
);
113+
foreach ($files as $filePath) {
114+
$this->mediaDirectory->delete(
115+
$catalogPath . '/cache/' . $cacheId . '/' . $filePath
116+
);
117+
}
117118
}
118119
}
119120
}

0 commit comments

Comments
 (0)