File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
app/code/Magento/Catalog/Helper
dev/tests/integration/testsuite/Magento/Catalog/Helper Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -251,12 +251,18 @@ public function getSmallImageUrl($product)
251
251
* Retrieve thumbnail image url
252
252
*
253
253
* @param ModelProduct|\Magento\Framework\DataObject $product
254
- * @return string
255
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
254
+ * @return string|bool
256
255
*/
257
256
public function getThumbnailUrl ($ product )
258
257
{
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 ;
260
266
}
261
267
262
268
/**
Original file line number Diff line number Diff line change @@ -90,13 +90,13 @@ public function testGetSmallImageUrl()
90
90
91
91
public function testGetThumbnailUrl ()
92
92
{
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
99
96
);
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 ));
100
100
}
101
101
102
102
public function testGetEmailToFriendUrl ()
You can’t perform that action at this time.
0 commit comments