7
7
8
8
namespace Magento \SendFriendGraphQl \Model \Resolver ;
9
9
10
- use Magento \Catalog \Api \Data \ProductInterface ;
11
- use Magento \Catalog \Api \ProductRepositoryInterface ;
12
10
use Magento \Framework \DataObjectFactory ;
13
11
use Magento \Framework \Event \ManagerInterface ;
14
- use Magento \Framework \Exception \NoSuchEntityException ;
15
12
use Magento \Framework \GraphQl \Config \Element \Field ;
16
13
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
17
- use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
18
14
use Magento \Framework \GraphQl \Query \ResolverInterface ;
19
15
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
20
16
use Magento \SendFriend \Model \SendFriend ;
21
17
use Magento \SendFriend \Model \SendFriendFactory ;
18
+ use Magento \SendFriendGraphQl \Model \Provider \GetProduct ;
22
19
23
20
/**
24
21
* @inheritdoc
@@ -30,11 +27,6 @@ class SendEmailToFriend implements ResolverInterface
30
27
*/
31
28
private $ sendFriendFactory ;
32
29
33
- /**
34
- * @var ProductRepositoryInterface
35
- */
36
- private $ productRepository ;
37
-
38
30
/**
39
31
* @var DataObjectFactory
40
32
*/
@@ -45,22 +37,27 @@ class SendEmailToFriend implements ResolverInterface
45
37
*/
46
38
private $ eventManager ;
47
39
40
+ /**
41
+ * @var GetProduct
42
+ */
43
+ private $ getProductProvider ;
44
+
48
45
/**
49
46
* @param SendFriendFactory $sendFriendFactory
50
- * @param ProductRepositoryInterface $productRepository
51
47
* @param DataObjectFactory $dataObjectFactory
52
48
* @param ManagerInterface $eventManager
49
+ * @param GetProduct $getProductProvider
53
50
*/
54
51
public function __construct (
55
52
SendFriendFactory $ sendFriendFactory ,
56
- ProductRepositoryInterface $ productRepository ,
57
53
DataObjectFactory $ dataObjectFactory ,
58
- ManagerInterface $ eventManager
54
+ ManagerInterface $ eventManager ,
55
+ GetProduct $ getProductProvider
59
56
) {
60
57
$ this ->sendFriendFactory = $ sendFriendFactory ;
61
- $ this ->productRepository = $ productRepository ;
62
58
$ this ->dataObjectFactory = $ dataObjectFactory ;
63
59
$ this ->eventManager = $ eventManager ;
60
+ $ this ->getProductProvider = $ getProductProvider ;
64
61
}
65
62
66
63
/**
@@ -77,7 +74,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
77
74
);
78
75
}
79
76
80
- $ product = $ this ->getProduct ($ args ['input ' ]['product_id ' ]);
77
+ $ product = $ this ->getProductProvider -> execute ($ args ['input ' ]['product_id ' ]);
81
78
$ this ->eventManager ->dispatch ('sendfriend_product ' , ['product ' => $ product ]);
82
79
$ sendFriend ->setProduct ($ product );
83
80
@@ -117,28 +114,6 @@ private function validateSendFriendModel(SendFriend $sendFriend, array $senderDa
117
114
}
118
115
}
119
116
120
- /**
121
- * Get product
122
- *
123
- * @param int $productId
124
- * @return ProductInterface
125
- * @throws GraphQlNoSuchEntityException
126
- */
127
- private function getProduct (int $ productId ): ProductInterface
128
- {
129
- try {
130
- $ product = $ this ->productRepository ->getById ($ productId );
131
- if (!$ product ->isVisibleInCatalog ()) {
132
- throw new GraphQlNoSuchEntityException (
133
- __ ("The product that was requested doesn't exist. Verify the product and try again. " )
134
- );
135
- }
136
- } catch (NoSuchEntityException $ e ) {
137
- throw new GraphQlNoSuchEntityException (__ ($ e ->getMessage ()), $ e );
138
- }
139
- return $ product ;
140
- }
141
-
142
117
/**
143
118
* Extract recipients data
144
119
*
0 commit comments