Skip to content

Commit 0d83afd

Browse files
authored
ENGCOM-6959: Fix: #26973 Fatal error when Product Image size is not defined #26974
2 parents 216e105 + 1c66d15 commit 0d83afd

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function getLabel(Product $product, string $imageType): string
123123
if (empty($label)) {
124124
$label = $product->getName();
125125
}
126-
return (string) $label;
126+
return (string)$label;
127127
}
128128

129129
/**
@@ -161,15 +161,15 @@ public function create(Product $product, string $imageId, array $attributes = nu
161161
}
162162

163163
$attributes = $attributes === null ? [] : $attributes;
164-
164+
165165
$data = [
166166
'data' => [
167167
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
168168
'image_url' => $imageAsset->getUrl(),
169169
'width' => $imageMiscParams['image_width'],
170170
'height' => $imageMiscParams['image_height'],
171171
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172-
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
172+
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
173173
'custom_attributes' => $this->getStringCustomAttributes($attributes),
174174
'class' => $this->getClass($attributes),
175175
'product_id' => $product->getId()

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageFactoryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function createDataProvider(): array
9595
return [
9696
$this->getTestDataWithoutAttributes(),
9797
$this->getTestDataWithAttributes(),
98+
$this->getTestDataWithoutDimensions()
9899
];
99100
}
100101

@@ -209,4 +210,21 @@ private function getTestDataWithAttributes(): array
209210
],
210211
];
211212
}
213+
214+
/**
215+
* @return array
216+
*/
217+
private function getTestDataWithoutDimensions(): array
218+
{
219+
$data = $this->getTestDataWithoutAttributes();
220+
221+
$data['data']['imageParamsBuilder']['image_width'] = null;
222+
$data['data']['imageParamsBuilder']['image_height'] = null;
223+
224+
$data['expected']['data']['width'] = null;
225+
$data['expected']['data']['height'] = null;
226+
$data['expected']['data']['ratio'] = 1.0;
227+
228+
return $data;
229+
}
212230
}

0 commit comments

Comments
 (0)