Skip to content

Commit 80e3d14

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4033' into PR_2025_07_10_chittima
2 parents af2ebc9 + d201e03 commit 80e3d14

File tree

7 files changed

+131
-9
lines changed

7 files changed

+131
-9
lines changed

app/code/Magento/GraphQl/Helper/Error/AggregateExceptionMessageFormatter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public function getFormatted(
5959
}
6060
}
6161

62-
$message = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
63-
return new GraphQlInputException($message, $e, $e->getCode());
62+
$messageText = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
63+
$messageWithPrefix = empty($messagePrefix)
64+
? $messageText
65+
: __("$messagePrefix: %message", ['message' => $messageText]);
66+
67+
return new GraphQlInputException($messageWithPrefix, $e, $e->getCode());
6468
}
6569
}

app/code/Magento/GraphQl/Test/Unit/Helper/Error/AggregateExceptionMessageFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testGetFormattedExceptionMessage(): void
118118
);
119119
$this->assertInstanceOf(GraphQlInputException::class, $exception);
120120
$this->assertSame($exceptionCode, $exception->getCode());
121-
$this->assertSame($exceptionMessage, $exception->getMessage());
121+
$this->assertSame($messagePrefix . ": " . $exceptionMessage, $exception->getMessage());
122122
}
123123

124124
/**
@@ -127,7 +127,7 @@ public function testGetFormattedExceptionMessage(): void
127127
public function testGetFormattedDefaultMessage(): void
128128
{
129129
$exceptionMessage = 'exception message';
130-
$messagePrefix = 'prefix';
130+
$messagePrefix = '';
131131
$this->formatter->expects($this->once())
132132
->method('getFormatted')
133133
->willReturn(null);

app/code/Magento/QuoteGraphQl/Model/ErrorMapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ErrorMapper
4343
'Please check the billing address information' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4444
'Enter a valid payment method and try again' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4545
'Some of the products are out of stock' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
46+
'Unable to place order' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4647
];
4748

4849
/**

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
7070
} catch (LocalizedException $exception) {
7171
$exception = $this->errorMessageFormatter->getFormatted(
7272
$exception,
73-
__('Unable to place order: A server error stopped your order from being placed. ' .
74-
'Please try to place your order again'),
73+
__('A server error stopped your order from being placed. Please try to place your order again'),
7574
'Unable to place order',
7675
$field,
7776
$context,
7877
$info
7978
);
8079
$exceptionCode = $exception->getCode();
8180
if (!$exceptionCode) {
82-
$exceptionCode = $this->errorMapper->getErrorMessageId($exception->getMessage());
81+
$exceptionCode = $this->errorMapper->getErrorMessageId($exception->getRawMessage());
8382
}
8483

8584
throw new QuoteException(__($exception->getMessage()), $exception, $exceptionCode);
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\GraphQl\Helper\Error\AggregateExceptionMessageFormatter;
14+
use Magento\GraphQl\Model\Query\Context;
15+
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
16+
use Magento\Quote\Model\Quote;
17+
use Magento\QuoteGraphQl\Model\Cart\GetCartForCheckout;
18+
use Magento\QuoteGraphQl\Model\Cart\PlaceOrder as PlaceOrderModel;
19+
use Magento\QuoteGraphQl\Model\ErrorMapper;
20+
use Magento\QuoteGraphQl\Model\QuoteException;
21+
use Magento\QuoteGraphQl\Model\Resolver\PlaceOrder;
22+
use Magento\Sales\Api\OrderRepositoryInterface;
23+
use Magento\SalesGraphQl\Model\Formatter\Order as OrderFormatter;
24+
use Magento\Store\Api\Data\StoreInterface;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
27+
28+
/**
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
*/
31+
class PlaceOrderTranslationTest extends TestCase
32+
{
33+
/**
34+
* @var GetCartForCheckout|MockObject
35+
*/
36+
private $getCartForCheckoutMock;
37+
38+
/**
39+
* @var PlaceOrderModel|MockObject
40+
*/
41+
private $placeOrderModelMock;
42+
43+
/**
44+
* @var AggregateExceptionMessageFormatter|MockObject
45+
*/
46+
private $errorMessageFormatterMock;
47+
48+
/**
49+
* @var ErrorMapper|MockObject
50+
*/
51+
private $errorMapperMock;
52+
53+
/**
54+
* @var PlaceOrder
55+
*/
56+
private $placeOrderResolver;
57+
58+
protected function setUp(): void
59+
{
60+
$this->getCartForCheckoutMock = $this->createMock(GetCartForCheckout::class);
61+
$this->placeOrderModelMock = $this->createMock(PlaceOrderModel::class);
62+
$this->errorMessageFormatterMock = $this->createMock(AggregateExceptionMessageFormatter::class);
63+
$this->errorMapperMock = $this->createMock(ErrorMapper::class);
64+
65+
$this->placeOrderResolver = new PlaceOrder(
66+
$this->getCartForCheckoutMock,
67+
$this->placeOrderModelMock,
68+
$this->createMock(OrderRepositoryInterface::class),
69+
$this->createMock(OrderFormatter::class),
70+
$this->errorMessageFormatterMock,
71+
$this->errorMapperMock
72+
);
73+
}
74+
75+
/**
76+
* Test that getRawMessage() is called on GraphQlInputException to map the error message properly.
77+
*/
78+
public function testGetRawMessageIsCalledForErrorMapping(): void
79+
{
80+
$exception = $this->getMockBuilder(GraphQlInputException::class)
81+
->disableOriginalConstructor()
82+
->onlyMethods(['getRawMessage'])
83+
->getMock();
84+
$exception->method('getRawMessage')->willReturn('Raw error message');
85+
$exception->expects($this->once())->method('getRawMessage');
86+
87+
$this->errorMapperMock->expects($this->once())
88+
->method('getErrorMessageId')
89+
->with('Raw error message')
90+
->willReturn(1);
91+
92+
$this->getCartForCheckoutMock->method('execute')->willReturn($this->createMock(Quote::class));
93+
$this->placeOrderModelMock->method('execute')->willThrowException($exception);
94+
$this->errorMessageFormatterMock->method('getFormatted')->willReturn($exception);
95+
96+
$contextMock = $this->createMock(Context::class);
97+
98+
$extensionAttributesMock = $this->getMockBuilder(ContextExtensionInterface::class)
99+
->disableOriginalConstructor()
100+
->addMethods(
101+
[
102+
'getStore',
103+
]
104+
)
105+
->getMock();
106+
$extensionAttributesMock->method('getStore')->willReturn($this->createMock(StoreInterface::class));
107+
$contextMock->method('getExtensionAttributes')->willReturn($extensionAttributesMock);
108+
109+
$this->expectException(QuoteException::class);
110+
$this->placeOrderResolver->resolve(
111+
$this->createMock(Field::class),
112+
$contextMock,
113+
$this->createMock(ResolveInfo::class),
114+
null,
115+
['input' => ['cart_id' => 'masked_cart_id']]
116+
);
117+
}
118+
}

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Guest/PlaceOrderWithPayflowLinkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function testResolveWithPayflowLinkDeclined(): void
248248
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
249249
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
250250
//Exception message is transformed into more controlled message
251-
$expectedErrorCode = 'UNDEFINED';
251+
$expectedErrorCode = 'UNABLE_TO_PLACE_ORDER';
252252

253253
$this->payflowRequest->method('setData')
254254
->with(

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Guest/PlaceOrderWithPaymentsAdvancedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function testResolveWithPaymentAdvancedDeclined(): void
208208
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
209209
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
210210
//Exception message is transformed into more controlled message
211-
$expectedErrorCode = 'UNDEFINED';
211+
$expectedErrorCode = 'UNABLE_TO_PLACE_ORDER';
212212

213213
$this->paymentRequest->method('setData')
214214
->with(

0 commit comments

Comments
 (0)