Skip to content

Commit 990f8ea

Browse files
Fix area for image placeholder in graphql response.
1 parent 072ef37 commit 990f8ea

File tree

1 file changed

+20
-4
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage

1 file changed

+20
-4
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Url.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\GraphQl\Config\Element\Field;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Framework\View\Asset\Repository as AssetRepository;
1617

1718
/**
1819
* Returns product's image url
@@ -23,14 +24,22 @@ class Url implements ResolverInterface
2324
* @var ImageFactory
2425
*/
2526
private $productImageFactory;
27+
/**
28+
* @var AssetRepository
29+
*/
30+
private $assetRepository;
2631

2732
/**
33+
* Url constructor.
2834
* @param ImageFactory $productImageFactory
35+
* @param AssetRepository $assetRepository
2936
*/
3037
public function __construct(
31-
ImageFactory $productImageFactory
38+
ImageFactory $productImageFactory,
39+
AssetRepository $assetRepository
3240
) {
3341
$this->productImageFactory = $productImageFactory;
42+
$this->assetRepository = $assetRepository;
3443
}
3544

3645
/**
@@ -55,8 +64,7 @@ public function resolve(
5564
$product = $value['model'];
5665
$imagePath = $product->getData($value['image_type']);
5766

58-
$imageUrl = $this->getImageUrl($value['image_type'], $imagePath);
59-
return $imageUrl;
67+
return $this->getImageUrl($value['image_type'], $imagePath);
6068
}
6169

6270
/**
@@ -71,7 +79,15 @@ private function getImageUrl(string $imageType, ?string $imagePath): string
7179
$image = $this->productImageFactory->create();
7280
$image->setDestinationSubdir($imageType)
7381
->setBaseFile($imagePath);
74-
$imageUrl = $image->getUrl();
82+
83+
$imageUrl = $image->isBaseFilePlaceholder()
84+
? $this->assetRepository->createAsset(
85+
"Magento_Catalog::images/product/placeholder/{$imageType}.jpg",
86+
['area' => \Magento\Framework\App\Area::AREA_FRONTEND]
87+
)
88+
->getUrl()
89+
: $image->getUrl();
90+
7591
return $imageUrl;
7692
}
7793
}

0 commit comments

Comments
 (0)