11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2025 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \SalesGraphQl \Model \Resolver ;
99
1010use Magento \Catalog \Model \Product ;
1111use Magento \CatalogGraphQl \Model \ProductDataProvider ;
12- use Magento \Framework \Exception \LocalizedException ;
1312use Magento \Framework \GraphQl \Config \Element \Field ;
1413use Magento \Framework \GraphQl \Query \ResolverInterface ;
1514use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
15+ use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
1616
1717/**
1818 * Fetches the Product data according to the GraphQL schema
1919 */
2020class ProductResolver implements ResolverInterface
2121{
2222 /**
23- * @var ProductDataProvider
24- */
25- private $ productDataProvider ;
26-
27- /**
23+ * ProductResolver Constructor
24+ *
2825 * @param ProductDataProvider $productDataProvider
2926 */
30- public function __construct (ProductDataProvider $ productDataProvider )
31- {
32- $ this -> productDataProvider = $ productDataProvider ;
27+ public function __construct (
28+ private readonly ProductDataProvider $ productDataProvider
29+ ) {
3330 }
3431
3532 /**
@@ -43,11 +40,13 @@ public function resolve(
4340 ?array $ args = null
4441 ) {
4542 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+ );
4746 }
4847 /** @var Product $product */
4948 $ product = $ value ['associatedProduct ' ];
5049
51- return $ this ->productDataProvider ->getProductDataById ((int ) $ product ->getId ());
50+ return $ this ->productDataProvider ->getProductDataById ((int )$ product ->getId ());
5251 }
5352}
0 commit comments