7
7
8
8
namespace Magento \CatalogGraphQl \Model \Resolver \Product ;
9
9
10
- use Magento \Catalog \Helper \ImageFactory as CatalogImageHelperFactory ;
11
10
use Magento \Catalog \Model \Product ;
11
+ use Magento \Catalog \Model \Product \ImageFactory ;
12
12
use Magento \Framework \GraphQl \Config \Element \Field ;
13
- use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
14
13
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
14
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
16
15
20
19
class Image implements ResolverInterface
21
20
{
22
21
/**
23
- * @var CatalogImageHelperFactory
22
+ * Product image factory
23
+ *
24
+ * @var ImageFactory
24
25
*/
25
- private $ catalogImageHelperFactory ;
26
+ private $ productImageFactory ;
26
27
27
28
/**
28
- * @param CatalogImageHelperFactory $catalogImageHelperFactory
29
+ * @param ImageFactory $productImageFactory
29
30
*/
30
31
public function __construct (
31
- CatalogImageHelperFactory $ catalogImageHelperFactory
32
+ ImageFactory $ productImageFactory
32
33
) {
33
- $ this ->catalogImageHelperFactory = $ catalogImageHelperFactory ;
34
+ $ this ->productImageFactory = $ productImageFactory ;
34
35
}
35
36
36
37
/**
@@ -44,22 +45,21 @@ public function resolve(
44
45
array $ args = null
45
46
): array {
46
47
if (!isset ($ value ['model ' ])) {
47
- throw new GraphQlInputException (__ ('"model" value should be specified ' ));
48
+ throw new \ LogicException (__ ('"model" value should be specified ' ));
48
49
}
49
50
/** @var Product $product */
50
51
$ product = $ value ['model ' ];
51
52
$ imageType = $ field ->getName ();
53
+ $ path = $ product ->getData ($ imageType );
52
54
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 ();
59
59
60
60
return [
61
61
'url ' => $ imageUrl ,
62
- 'path ' => $ product -> getData ( $ imageType )
62
+ 'path ' => $ path ,
63
63
];
64
64
}
65
65
}
0 commit comments