Skip to content

Commit 83ea21f

Browse files
authored
Added try-catch block in getSwatchAttributeImage
getSwatchAttributeImage calls generateSwatchVariations($file), which throws an Exception when the file $file does not exist in the file system (see line 189: $image = $this->imageFactory->create($absoluteImagePath), which calls Image->__construct() and then Image->open, throwing an Exception on !file_exists($file)). This leads to the rest of the page not being rendered, when just one swatch image is missing. Not great. This fixes it and returns an empty file url (could also return the intended one, or a placeholder).
1 parent 1e19c93 commit 83ea21f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/code/Magento/Swatches/Helper/Media.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ public function getSwatchAttributeImage($swatchType, $file)
109109
$absoluteImagePath = $this->mediaDirectory
110110
->getAbsolutePath($this->getSwatchMediaPath() . '/' . $generationPath);
111111
if (!file_exists($absoluteImagePath)) {
112-
$this->generateSwatchVariations($file);
112+
try {
113+
$this->generateSwatchVariations($file);
114+
} catch (\Exception $e) {
115+
return '';
116+
}
113117
}
114118
return $this->getSwatchMediaUrl() . '/' . $generationPath;
115119
}

0 commit comments

Comments
 (0)