Skip to content

Commit 1b3587f

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70391: Return URL in getThumbnailUrl instead of nothing #10106
2 parents 98f3fea + bbbc9fe commit 1b3587f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

app/code/Magento/Catalog/Helper/Product.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,18 @@ public function getSmallImageUrl($product)
251251
* Retrieve thumbnail image url
252252
*
253253
* @param ModelProduct|\Magento\Framework\DataObject $product
254-
* @return string
255-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
254+
* @return string|bool
256255
*/
257256
public function getThumbnailUrl($product)
258257
{
259-
return '';
258+
$url = false;
259+
$attribute = $product->getResource()->getAttribute('thumbnail');
260+
if (!$product->getThumbnail()) {
261+
$url = $this->_assetRepo->getUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg');
262+
} elseif ($attribute) {
263+
$url = $attribute->getFrontend()->getUrl($product);
264+
}
265+
return $url;
260266
}
261267

262268
/**

dev/tests/integration/testsuite/Magento/Catalog/Helper/ProductTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public function testGetSmallImageUrl()
9090

9191
public function testGetThumbnailUrl()
9292
{
93-
$this->assertEmpty(
94-
$this->helper->getThumbnailUrl(
95-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
96-
\Magento\Catalog\Model\Product::class
97-
)
98-
)
93+
/** @var $product \Magento\Catalog\Model\Product */
94+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
95+
\Magento\Catalog\Model\Product::class
9996
);
97+
$this->assertStringEndsWith('placeholder/thumbnail.jpg', $this->helper->getThumbnailUrl($product));
98+
$product->setThumbnail('test_image.png');
99+
$this->assertStringEndsWith('/test_image.png', $this->helper->getThumbnailUrl($product));
100100
}
101101

102102
public function testGetEmailToFriendUrl()

0 commit comments

Comments
 (0)