16
16
use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
17
17
use Magento \SendFriend \Model \SendFriend ;
18
18
use Magento \SendFriend \Model \SendFriendFactory ;
19
+ use Magento \SendFriendGraphQl \Model \Provider \GetVisibleProduct ;
19
20
20
21
/**
21
22
* Send Product Email to Friend(s)
@@ -43,21 +44,30 @@ class SendEmail
43
44
private $ eventManager ;
44
45
45
46
/**
47
+ * @var GetVisibleProduct
48
+ */
49
+ private $ visibleProductProvider ;
50
+
51
+ /**
52
+ * SendEmail constructor.
46
53
* @param DataObjectFactory $dataObjectFactory
47
54
* @param ProductRepositoryInterface $productRepository
48
55
* @param SendFriendFactory $sendFriendFactory
49
56
* @param ManagerInterface $eventManager
57
+ * @param GetVisibleProduct $visibleProductProvider
50
58
*/
51
59
public function __construct (
52
60
DataObjectFactory $ dataObjectFactory ,
53
61
ProductRepositoryInterface $ productRepository ,
54
62
SendFriendFactory $ sendFriendFactory ,
55
- ManagerInterface $ eventManager
63
+ ManagerInterface $ eventManager ,
64
+ GetVisibleProduct $ visibleProductProvider
56
65
) {
57
66
$ this ->dataObjectFactory = $ dataObjectFactory ;
58
67
$ this ->productRepository = $ productRepository ;
59
68
$ this ->sendFriendFactory = $ sendFriendFactory ;
60
69
$ this ->eventManager = $ eventManager ;
70
+ $ this ->visibleProductProvider = $ visibleProductProvider ;
61
71
}
62
72
63
73
/**
@@ -81,7 +91,7 @@ public function execute(int $productId, array $senderData, array $recipientsData
81
91
);
82
92
}
83
93
84
- $ product = $ this ->getProduct ($ productId );
94
+ $ product = $ this ->visibleProductProvider -> execute ($ productId );
85
95
86
96
$ this ->eventManager ->dispatch ('sendfriend_product ' , ['product ' => $ product ]);
87
97
@@ -117,26 +127,4 @@ private function validateSendFriendModel(SendFriend $sendFriend, array $senderDa
117
127
throw new GraphQlInputException (__ (implode ($ validationResult )));
118
128
}
119
129
}
120
-
121
- /**
122
- * Get product
123
- *
124
- * @param int $productId
125
- * @return ProductInterface
126
- * @throws GraphQlNoSuchEntityException
127
- */
128
- private function getProduct (int $ productId ): ProductInterface
129
- {
130
- try {
131
- $ product = $ this ->productRepository ->getById ($ productId );
132
- if (!$ product ->isVisibleInCatalog ()) {
133
- throw new GraphQlNoSuchEntityException (
134
- __ ("The product that was requested doesn't exist. Verify the product and try again. " )
135
- );
136
- }
137
- } catch (NoSuchEntityException $ e ) {
138
- throw new GraphQlNoSuchEntityException (__ ($ e ->getMessage ()), $ e );
139
- }
140
- return $ product ;
141
- }
142
130
}
0 commit comments