10
10
use Magento \Framework \Exception \AuthorizationException ;
11
11
use Magento \Framework \Exception \LocalizedException ;
12
12
use Magento \Framework \GraphQl \Config \Element \Field ;
13
- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
14
13
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
15
14
use Magento \Framework \GraphQl \Query \ResolverInterface ;
16
15
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
17
- use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
18
16
use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
19
17
use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
20
- use Magento \QuoteGraphQl \Model \ErrorMapper ;
21
- use Magento \QuoteGraphQl \Model \QuoteException ;
18
+ use Magento \QuoteGraphQl \Model \OrderErrorProcessor ;
22
19
use Magento \Sales \Api \OrderRepositoryInterface ;
23
20
use Magento \SalesGraphQl \Model \Formatter \Order as OrderFormatter ;
24
21
25
22
/**
26
23
* Resolver for placing order after payment method has already been set
27
- *
28
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
29
24
*/
30
25
class PlaceOrder implements ResolverInterface
31
26
{
@@ -34,16 +29,14 @@ class PlaceOrder implements ResolverInterface
34
29
* @param PlaceOrderModel $placeOrder
35
30
* @param OrderRepositoryInterface $orderRepository
36
31
* @param OrderFormatter $orderFormatter
37
- * @param AggregateExceptionMessageFormatter $errorMessageFormatter
38
- * @param ErrorMapper $errorMapper
32
+ * @param OrderErrorProcessor $orderErrorProcessor
39
33
*/
40
34
public function __construct (
41
35
private readonly GetCartForCheckout $ getCartForCheckout ,
42
36
private readonly PlaceOrderModel $ placeOrder ,
43
37
private readonly OrderRepositoryInterface $ orderRepository ,
44
38
private readonly OrderFormatter $ orderFormatter ,
45
- private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter ,
46
- private readonly ErrorMapper $ errorMapper
39
+ private readonly OrderErrorProcessor $ orderErrorProcessor
47
40
) {
48
41
}
49
42
@@ -63,26 +56,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
63
56
$ cart = $ this ->getCartForCheckout ->execute ($ maskedCartId , $ userId , $ storeId );
64
57
$ orderId = $ this ->placeOrder ->execute ($ cart , $ maskedCartId , $ userId );
65
58
$ order = $ this ->orderRepository ->get ($ orderId );
66
- } catch (AuthorizationException $ exception ) {
67
- throw new GraphQlAuthorizationException (
68
- __ ($ exception ->getMessage ())
69
- );
70
- } catch (LocalizedException $ exception ) {
71
- $ exception = $ this ->errorMessageFormatter ->getFormatted (
72
- $ exception ,
73
- __ ('Unable to place order: A server error stopped your order from being placed. ' .
74
- 'Please try to place your order again ' ),
75
- 'Unable to place order ' ,
76
- $ field ,
77
- $ context ,
78
- $ info
79
- );
80
- $ exceptionCode = $ exception ->getCode ();
81
- if (!$ exceptionCode ) {
82
- $ exceptionCode = $ this ->errorMapper ->getErrorMessageId ($ exception ->getMessage ());
83
- }
84
-
85
- throw new QuoteException (__ ($ exception ->getMessage ()), $ exception , $ exceptionCode );
59
+ } catch (AuthorizationException |LocalizedException $ exception ) {
60
+ return $ this ->orderErrorProcessor ->execute ($ exception , $ field , $ context , $ info );
86
61
}
87
62
88
63
return [
@@ -91,7 +66,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
91
66
// @deprecated The order_id field is deprecated, use order_number instead
92
67
'order_id ' => $ order ?->getIncrementId(),
93
68
],
94
- 'orderV2 ' => $ order ? $ this ->orderFormatter ->format ($ order ) : null
69
+ 'orderV2 ' => $ order ? $ this ->orderFormatter ->format ($ order ) : null ,
95
70
];
96
71
}
97
72
}
0 commit comments