Skip to content

Commit 2bfc225

Browse files
author
Valeriy Nayda
committed
Merge branch 'ENGCOM-2948-magento-graphql-ce-132' into graphql-develop-prs
2 parents c5c8ea5 + 669375c commit 2bfc225

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Image.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Product;
99

10-
use Magento\Catalog\Helper\ImageFactory as CatalogImageHelperFactory;
1110
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\Product\ImageFactory;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
13-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1615

@@ -20,17 +19,19 @@
2019
class Image implements ResolverInterface
2120
{
2221
/**
23-
* @var CatalogImageHelperFactory
22+
* Product image factory
23+
*
24+
* @var ImageFactory
2425
*/
25-
private $catalogImageHelperFactory;
26+
private $productImageFactory;
2627

2728
/**
28-
* @param CatalogImageHelperFactory $catalogImageHelperFactory
29+
* @param ImageFactory $productImageFactory
2930
*/
3031
public function __construct(
31-
CatalogImageHelperFactory $catalogImageHelperFactory
32+
ImageFactory $productImageFactory
3233
) {
33-
$this->catalogImageHelperFactory = $catalogImageHelperFactory;
34+
$this->productImageFactory = $productImageFactory;
3435
}
3536

3637
/**
@@ -44,22 +45,21 @@ public function resolve(
4445
array $args = null
4546
): array {
4647
if (!isset($value['model'])) {
47-
throw new GraphQlInputException(__('"model" value should be specified'));
48+
throw new \LogicException(__('"model" value should be specified'));
4849
}
4950
/** @var Product $product */
5051
$product = $value['model'];
5152
$imageType = $field->getName();
53+
$path = $product->getData($imageType);
5254

53-
$catalogImageHelper = $this->catalogImageHelperFactory->create();
54-
$imageUrl = $catalogImageHelper->init(
55-
$product,
56-
'product_' . $imageType,
57-
['type' => $imageType]
58-
)->getUrl();
55+
$image = $this->productImageFactory->create();
56+
$image->setDestinationSubdir($imageType)
57+
->setBaseFile($path);
58+
$imageUrl = $image->getUrl();
5959

6060
return [
6161
'url' => $imageUrl,
62-
'path' => $product->getData($imageType)
62+
'path' => $path,
6363
];
6464
}
6565
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/MediaGalleryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function testProductSmallImageUrlWithExistingImage()
3131
{
3232
products(filter: {sku: {eq: "{$productSku}"}}) {
3333
items {
34-
small_image {
35-
url
36-
}
34+
small_image {
35+
url
36+
}
3737
}
3838
}
3939
}

0 commit comments

Comments
 (0)