Skip to content

Commit 1c1c47e

Browse files
authored
Merge pull request #9986 from magento-cia/cia-2.4.9-alpha3-develop-bugfix-08042025
Cia 2.4.9 alpha3 develop Bugfix Delivery 08042025
2 parents eb05acf + f26acec commit 1c1c47e

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/EstimateTotals.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Checkout\Api\Data\TotalsInformationInterface;
1111
use Magento\Checkout\Api\TotalsInformationManagementInterface;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\Exception\NoSuchEntityException;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
1415
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
@@ -20,12 +21,19 @@
2021
use Magento\QuoteGraphQl\Model\ErrorMapper;
2122
use Magento\QuoteGraphQl\Model\TotalsBuilder;
2223
use Psr\Log\LoggerInterface;
24+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
2325

2426
/**
2527
* Apply address and shipping method to totals estimate and return the quote
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2629
*/
2730
class EstimateTotals implements ResolverInterface
2831
{
32+
/**
33+
* @var GetCartForUser
34+
*/
35+
private GetCartForUser $getCartForUser;
36+
2937
/**
3038
* EstimateTotals Constructor
3139
*
@@ -36,6 +44,7 @@ class EstimateTotals implements ResolverInterface
3644
* @param AssignShippingMethodToCart $assignShippingMethodToCart
3745
* @param LoggerInterface $logger
3846
* @param TotalsBuilder $totalsBuilder
47+
* @param GetCartForUser|null $getCartForUser
3948
*/
4049
public function __construct(
4150
private readonly MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
@@ -44,8 +53,10 @@ public function __construct(
4453
private readonly ErrorMapper $errorMapper,
4554
private readonly AssignShippingMethodToCart $assignShippingMethodToCart,
4655
private readonly LoggerInterface $logger,
47-
private readonly TotalsBuilder $totalsBuilder
56+
private readonly TotalsBuilder $totalsBuilder,
57+
?GetCartForUser $getCartForUser = null
4858
) {
59+
$this->getCartForUser = $getCartForUser ?? ObjectManager::getInstance()->get(GetCartForUser::class);
4960
}
5061

5162
/**
@@ -54,19 +65,20 @@ public function __construct(
5465
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
5566
{
5667
$input = $args['input'] ?? [];
68+
$maskedCartId = $input['cart_id'];
5769

58-
if (empty($input['cart_id'])) {
70+
if (empty($maskedCartId)) {
5971
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
6072
}
6173

6274
try {
63-
$cartId = $this->maskedQuoteIdToQuoteId->execute($input['cart_id']);
75+
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId);
6476
} catch (NoSuchEntityException $exception) {
6577
throw new GraphQlInputException(
6678
__(
6779
'Could not find a cart with ID "%masked_id"',
6880
[
69-
'masked_id' => $input['cart_id']
81+
'masked_id' => $maskedCartId
7082
]
7183
),
7284
$exception,
@@ -79,6 +91,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
7991
throw new GraphQlInputException(__('Required parameter "country_code" is missing'));
8092
}
8193

94+
$currentUserId = $context->getUserId();
95+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
96+
$this->getCartForUser->execute($maskedCartId, $currentUserId, $storeId);
97+
8298
$totalsInfo = $this->totalsBuilder->execute($addressData, $input['shipping_method'] ?? []);
8399
$this->totalsInformationManagement->calculate($cartId, $totalsInfo);
84100
$this->updateShippingMethod($totalsInfo, $cartId);

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EstimateTotalsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote;
99

10+
use Exception;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Tax\Test\Fixture\ProductTaxClass;
1213
use Magento\Tax\Test\Fixture\TaxRate as TaxRateFixture;
@@ -262,4 +263,37 @@ public static function estimationsProvider(): array
262263
]
263264
];
264265
}
266+
267+
/**
268+
* Test invalid cart ID error handling
269+
*/
270+
public function testEstimateTotalsWithInvalidCartId(): void
271+
{
272+
$invalidCartId = 'abcxyz';
273+
274+
$this->expectException(Exception::class);
275+
$this->expectExceptionMessage('Could not find a cart with ID "' . $invalidCartId . '"');
276+
277+
$query = <<<QUERY
278+
mutation {
279+
estimateTotals(input: {
280+
cart_id: "{$invalidCartId}",
281+
address: {
282+
country_code: US
283+
}
284+
}) {
285+
cart {
286+
prices {
287+
grand_total {
288+
value
289+
currency
290+
}
291+
}
292+
}
293+
}
294+
}
295+
QUERY;
296+
297+
$this->graphQlMutation($query);
298+
}
265299
}

0 commit comments

Comments
 (0)