Skip to content

Commit 1630277

Browse files
authored
LYNX-698 Error when item in return is out of stock
1 parent 6d814cc commit 1630277

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
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
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Resolver;
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\CatalogGraphQl\Model\ProductDataProvider;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use 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
*/
2020
class 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

Comments
 (0)