Skip to content

Fix: #26973 Fatal error when Product Image size is not defined #26974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Block/Product/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function getLabel(Product $product, string $imageType): string
if (empty($label)) {
$label = $product->getName();
}
return (string) $label;
return (string)$label;
}

/**
Expand Down Expand Up @@ -161,15 +161,15 @@ public function create(Product $product, string $imageId, array $attributes = nu
}

$attributes = $attributes === null ? [] : $attributes;

$data = [
'data' => [
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
'image_url' => $imageAsset->getUrl(),
'width' => $imageMiscParams['image_width'],
'height' => $imageMiscParams['image_height'],
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
'custom_attributes' => $this->getStringCustomAttributes($attributes),
'class' => $this->getClass($attributes),
'product_id' => $product->getId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function createDataProvider(): array
return [
$this->getTestDataWithoutAttributes(),
$this->getTestDataWithAttributes(),
$this->getTestDataWithoutDimensions()
];
}

Expand Down Expand Up @@ -209,4 +210,21 @@ private function getTestDataWithAttributes(): array
],
];
}

/**
* @return array
*/
private function getTestDataWithoutDimensions(): array
{
$data = $this->getTestDataWithoutAttributes();

$data['data']['imageParamsBuilder']['image_width'] = null;
$data['data']['imageParamsBuilder']['image_height'] = null;

$data['expected']['data']['width'] = null;
$data['expected']['data']['height'] = null;
$data['expected']['data']['ratio'] = 1.0;

return $data;
}
}