1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2025 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \SalesGraphQl \Model \Resolver ;
9
9
10
10
use Magento \Catalog \Model \Product ;
11
11
use Magento \CatalogGraphQl \Model \ProductDataProvider ;
12
- use Magento \Framework \Exception \LocalizedException ;
13
12
use Magento \Framework \GraphQl \Config \Element \Field ;
14
13
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
14
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
15
+ use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
16
16
17
17
/**
18
18
* Fetches the Product data according to the GraphQL schema
19
19
*/
20
20
class ProductResolver implements ResolverInterface
21
21
{
22
22
/**
23
- * @var ProductDataProvider
24
- */
25
- private $ productDataProvider ;
26
-
27
- /**
23
+ * ProductResolver Constructor
24
+ *
28
25
* @param ProductDataProvider $productDataProvider
29
26
*/
30
- public function __construct (ProductDataProvider $ productDataProvider )
31
- {
32
- $ this -> productDataProvider = $ productDataProvider ;
27
+ public function __construct (
28
+ private readonly ProductDataProvider $ productDataProvider
29
+ ) {
33
30
}
34
31
35
32
/**
@@ -43,11 +40,13 @@ public function resolve(
43
40
?array $ args = null
44
41
) {
45
42
if (!isset ($ value ['associatedProduct ' ])) {
46
- throw new LocalizedException (__ ('Missing key "associatedProduct" in Order Item value data ' ));
43
+ throw new GraphQlNoSuchEntityException (
44
+ __ ("This product is currently out of stock or not available. " )
45
+ );
47
46
}
48
47
/** @var Product $product */
49
48
$ product = $ value ['associatedProduct ' ];
50
49
51
- return $ this ->productDataProvider ->getProductDataById ((int ) $ product ->getId ());
50
+ return $ this ->productDataProvider ->getProductDataById ((int )$ product ->getId ());
52
51
}
53
52
}
0 commit comments